.buttons > * {
transition: transform 700ms;
}
.buttons > .one.closed {
transform: translateY(-10vh);
}
.buttons > .two.closed {
transform: translateY(-20vh);
}
.buttons > .three.closed {
transform: translateY(-30vh);
}
I have this code, on click i add .closed class to the three elements, is there a way to achieve the same effect without writing the css rule n times?
(我有这段代码,单击后将.closed类添加到这三个元素中,有没有一种方法可以在不编写css规则n次的情况下达到相同的效果?)
I'm fine with doing it through js (我很好用js来做)
This for example doesn't work :
(例如,这不起作用:)
const menuElements = document.querySelectorAll(".buttons > :not(.main)");
menuElements.forEach((el, key) => {
el.setAttribute("transform", -10 * key + "vh");
el.classList.toggle("closed");
});
JSFiddle : https://jsfiddle.net/1cofL06p/
(JSFiddle: https ://jsfiddle.net/1cofL06p/)
ask by Zee translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…