我有jQuery冲突,想知道是否有人可以帮助我将这小段代码转换为普通的javascript。真的很感激。提前谢谢
$('.menuH').hover(function() {
$('.menuC').stop().animate({
width: '90px'
}, 333)
}, function() {
$('.menuC').stop().animate({
width: '-0'
}, 333)
});
答案 0 :(得分:1)
我还没有对此进行过测试,但是,可能还有这些方法吗?
var menuh_el = document.getElementById('.menuH');
menuh_el.onmouseover = function() {
var time = Date.now();
var interval = setInterval(function() {
if ((Date.now() - time) < 333) {
menuh_el.width = (((Date.now() - time) / 333) * 90) + "px";
} else {
menuh_el.width = "90px";
clearInterval(interval);
}
}, 10);
};
menuh_el.onmouseout = function() {
var time = Date.now();
var interval = setInterval(function() {
if ((Date.now() - time) < 333) {
menuh_el.width = (((time - Date.now()) / 333) * 90) + "px";
} else {
menuh_el.width = "0px";
clearInterval(interval);
}
}, 10);
};
尽管如此,您应该用setInterval
代替requestAnimationFrame
。此外,它在jQuery代码中的区别在于它不会调用.stop()
,我不知道该怎么做,我很抱歉:(