我想在纯JavaScript中重写下面的jQuery代码以节省加载时间。
Here is the link to the demo page
var playstate = function (){
$(".magicwand").addClass("logo-effect");
setTimeout(function () {
$(".magicwand").removeClass("logo-effect");
}, 6000);
}
playstate();
setInterval(playstate, 6100);
答案 0 :(得分:0)
试试这个:我已经将你的jquery代码转换为纯javascript。
var playstate = function() {
var element = document.getElementsByClassName("magicwand");
element[0].classList.add("logo-effect");
setInterval(function() {
var element = document.getElementsByClassName("magicwand");
element[0].classList.remove("logo-effect");
}, 6000);
}
playstate();
setInterval(playstate, 6100);

<div class="magicwand">test</div>
&#13;