admin管理员组文章数量:1287963
I have a burgermenu with an overlay using toggle to activate the overlay (upper right):
/
I used JS to rotate the burgermenu on toggle... the overlay/menu slides down .but i cant get it it to rotate back to the original position on a second toggle as the overlay/menu clears
my script (what I was trying is in bold):
const bento_box_wrapper = document.querySelector('.bento_box_wrapper');
const bento_box = document.querySelectorAll('.bento_box');
bento_box_wrapper.onclick = function() {
const overlayWrapper = document.querySelector('.overlayWrapper');
overlayWrapper.classList.toggle('overlayWrapperSlideDown');
$('.bento_box_wrapper').addClass('blur');
bento_box_wrapper.style.transform = 'rotate(315deg)';
$('div#toggle').addClass('blur');
const mainNavLinksWrapper = document.querySelector('.mainNavLinksWrapper');
mainNavLinksWrapper.classList.toggle('mainNavLinksWrapperSlideUp');
**bento_box_wrapper.classList.toggle = 'rotate(45 deg)';**
}
I have a burgermenu with an overlay using toggle to activate the overlay (upper right):
https://pitchlab/
I used JS to rotate the burgermenu on toggle... the overlay/menu slides down .but i cant get it it to rotate back to the original position on a second toggle as the overlay/menu clears
my script (what I was trying is in bold):
const bento_box_wrapper = document.querySelector('.bento_box_wrapper');
const bento_box = document.querySelectorAll('.bento_box');
bento_box_wrapper.onclick = function() {
const overlayWrapper = document.querySelector('.overlayWrapper');
overlayWrapper.classList.toggle('overlayWrapperSlideDown');
$('.bento_box_wrapper').addClass('blur');
bento_box_wrapper.style.transform = 'rotate(315deg)';
$('div#toggle').addClass('blur');
const mainNavLinksWrapper = document.querySelector('.mainNavLinksWrapper');
mainNavLinksWrapper.classList.toggle('mainNavLinksWrapperSlideUp');
**bento_box_wrapper.classList.toggle = 'rotate(45 deg)';**
}
Share
Improve this question
asked Feb 23 at 4:03
REELHEROREELHERO
371 silver badge10 bronze badges
3
- 2 You might find reading the site help section useful when it comes to asking a good question. To get the best answers to your question we like to see that you've attempted to solve the problem yourself first using a minimal reproducible example. Here's a question checklist you might find useful... – Mister Jojo Commented Feb 23 at 5:36
- 1 It would be better to create a class and toggle the class on click as you are doing for .mainNavLinksWrapperSlideUp; If you want different rotations on click you can create 2 differents classes and then add or remove them (if element contains that class on click) – Mehdi Commented Feb 23 at 11:14
- copy that. I thought I was doing that above by showing the code I was using. I guess I shouldve created a snippet. apologies. – REELHERO Commented Feb 23 at 16:07
1 Answer
Reset to default 0You can set transform
attribute of the element to rotate(0)
. Something like below should handle your case:
var angle = bento_box_wrapper.style.transform !== 'rotate(45deg)' ? 45 : 0;
bento_box_wrapper.style.transform = 'rotate(' + angle + 'deg)';
本文标签: javascriptreturn event on second toggleStack Overflow
版权声明:本文标题:javascript - return event on second toggle - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741321115a2372210.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论