类列表 onclick 的多重切换
大家好,这是我在这个网站上的第一篇文章,我想知道是否可以有多个 classList,并且每次单击元素时都会切换,并在最后一个 classList 之后循环,
这是我的 css:
:root {
--primCol: #fff;
}
.dark-theme{
--primCol: #9A4747;
}
body {
display: inline-flex;
width: 100vw;
height: 100vh;
background-color: var(--primCol);
margin: 0;
padding: 0;
justify-content: center;
align-items: center;
transition: all .5s;
}
#wrapper {
transition: all .7s;
border-radius: 5px;
cursor: pointer;
-webkit-tap-highlight-color: transparent;
background-color: var(--primCol);
width: 300px;
height: 300px;
box-shadow: 0 0 10px #B8B8B8;
}
#wrapper:active {
transform: scale(1.3);
}
我的 jQuery:
$(document).ready(() => {
$('#wrapper').click( () => {
document.body.classList.toggle("dark-theme");
});
});
good day everyone this is my first post on this site, i am wondering if it's possible to have multiple classList, and will be toggle each click on the element and loop after the last classList
here's my css:
:root {
--primCol: #fff;
}
.dark-theme{
--primCol: #9A4747;
}
body {
display: inline-flex;
width: 100vw;
height: 100vh;
background-color: var(--primCol);
margin: 0;
padding: 0;
justify-content: center;
align-items: center;
transition: all .5s;
}
#wrapper {
transition: all .7s;
border-radius: 5px;
cursor: pointer;
-webkit-tap-highlight-color: transparent;
background-color: var(--primCol);
width: 300px;
height: 300px;
box-shadow: 0 0 10px #B8B8B8;
}
#wrapper:active {
transform: scale(1.3);
}
my jQuery:
$(document).ready(() => {
$('#wrapper').click( () => {
document.body.classList.toggle("dark-theme");
});
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个。然后,使用
::root
中的变量为元素提供样式。Try this. Then, use variables from your
::root
to give styles to elements.