$( ".menuicon" ).mouseenter(function() {
$(this).animate({
width: '100px'
}, 300);
});
$( ".menuicon" ).mouseover(function() {
$(this).animate({
width: '36px'
}, 300);
});
鼠标悬停时图标的宽度更改为100px,但很快就会恢复到36px,鼠标仍在其上。
答案 0 :(得分:3)
您需要使用mouseleave
事件,而不是mouseover
:
$(".menuicon").mouseleave(function() {
$(this).stop(true).animate({
width: '36px'
}, 300);
});
或者更好的是,将整个事情结合起来使用hover
:
$(".menuicon").hover(
function() { $(this).stop(true).animate({ width: '100px' }, 300); },
function() { $(this).stop(true).animate({ width: '36px' }, 300); }
);
答案 1 :(得分:1)
使用 mouseleave() 代替 mouseover() ,
$( ".menuicon" ).mouseleave(function() {
$(this).animate({
width: '36px'
}, 300);
});
或者尝试 hover() ,
$( ".menuicon" ).hover(function() {
$(this).animate({
width: '100px'
}, 300);
},function() {
$(this).animate({
width: '36px'
}, 300);
});
答案 2 :(得分:0)
$( ".menuicon" ).hover(function() {
$(this).animate({
width: '100px'
}, 300);
},function() {
$(this).animate({
width: '36px'
}, 300);
});