javascript - Toggle up and down arrows in a simple accordion widget -
i have followed few tutorials , created simple accordion widget, works fine can see in fiddle
however, trying add downward arrow when section closed , upper arrow when section open - @ right end of head of each tab in accordion, image below shows:
here arrows font codes:
.icon-arrowup:before { content: "\f077"; } .icon-arrowdown:before { content: "\f078"; }
here have tried, added downward arrow default using css:
.accordian .accordian-head:before { font-family: 'icons'; content: "\f078"; float: right; }
this added arrow nicely, want replace arrow upward 1 when section open, have no clue do! tried add following css , toggle javascript, didn't work:
.accordian .accordian-head .accordian-head-active:before { font-family: 'icons'; content: "\f077"; background-color: red; } //accordian $('.accordion').each(function () { var $accordian = $(this); $accordian.find('.accordion-head').on('click', function () { $accordian.find('.accordion-body').slideup(); if (!$(this).next().is(':visible')) { $(this).next().slidedown(); $(this).addclass('accordian-head-active'); } }); });
i have using css border - arrow
js
$('.accordion').each(function () { var $accordian = $(this); $accordian.find('.accordion-head').on('click', function () { $accordian.find('.accordion-body').slideup(); if (!$(this).next().is(':visible')) { $(this).next().slidedown(); $('h4 span',this).text("up arrow"); }else{ $('h4 span',this).text("down arrow"); } }); });
added css
.arrow { float: right; width: 0px; height: 0px; margin-top: 23px; border: 10px solid transparent; margin-top: 21px; border-top-color: #f3f3f3; } .accordion-head.open .arrow { margin-top: 11px; border-bottom-color: #f3f3f3; border-top-color: transparent; }
Comments
Post a Comment