[英]How to Transform / Reverse SVG Icon When it is Used as a Click Icon in Accordion Menu
I'm trying to create accordion menu with jQuery and SVG.我正在尝试使用 jQuery 和 SVG 创建手风琴菜单。
Then, I attempt to use SVG Arrow Icon as a click button, but然后,我尝试使用 SVG Arrow Icon 作为点击按钮,但是
I can not make the Icon rotate flexibly.我不能让图标灵活旋转。
Here is my Codepen .这是我的Codepen 。
//SVG Arrow Icon
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
viewBox="0 0 48 48" enable-background="new 0 0 48 48" width="30" height="30" class="svg_arrow">
<rect class="st0" width="30" height="30"/>
<path class="st1" d="M16,28l7.5-7.5c0.9-0.9,2.2-0.9,3.1,0L34,28" stroke="#2dac9a"/>
</svg>
//SVG CSS
svg{
fill: #2dac9a;
position: absolute;
top: 15px;
right: 10px;
transform: rotate(180deg);
}
.tr{
transform: rotate(0deg);
}
$('.faq_accordion').on('click', function () {
$(this).children().eq(1).slideToggle(300);
$(this).children('.faq_li').toggleClass('b');
$(this).children('.faq_li').find('svg')[0].setAttribute('class', 'tr'); //does not work...
$(".faq_accordion .faq_answer").not($(this).children().eq(1)).slideUp(300);
});
When I click the SVG Arrow Icon, the 'setAttribute' Method works,当我单击 SVG 箭头图标时,“setAttribute”方法起作用,
but I do not know how to reverse position when I click it once again.但是当我再次单击它时,我不知道如何反转位置。
It seems to me that 'toggleAttribute' method also does not work...(I tried it.)在我看来,'toggleAttribute' 方法也不起作用......(我试过了。)
I appreciate if you teach me the effective way.如果你教我有效的方法,我很感激。
I 'm sorry if this question is already solved in another section.如果这个问题已经在另一个部分解决了,我很抱歉。
Thank you.谢谢你。
.tr{
transform: rotate(0deg);
} // revome this
svg{
fill: #2dac9a;
position: absolute;
top: 15px;
right: 10px;
transform: rotate(180deg);
transition: transform 300ms; // Add this
}
.b svg {
transform: rotate(0deg);
} // Add this
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.