如果你真的想使用jQuery(不CSS转换),然后用.hover
, .fadeIn
和.fadeOut
和我对
的理解
我希望它再次运行并再次每次用户通过它从它
$(".change-profile-pic").hide();
$('.img-with-border').hover(
function over() { // fade in on mouseover
$('.change-profile-pic').fadeIn(500);
},
function out() { // fade out on mouseout
$('.change-profile-pic').fadeOut(500);
}
);
编辑将鼠标移动和离开没有淡出悬停时在.change-profile-pic
(function setUpHover() {
$(".change-profile-pic").hide();
var timeout = null,
over = function over() {
window.clearTimeout(timeout);
$('.change-profile-pic').fadeIn(500);
},
outAfterDelay = function outAfterDelay() {
$('.change-profile-pic').fadeOut(500);
},
out = function out() {
timeout = window.setTimeout(outAfterDelay, 1000); // give enough time to move to elm here
};
$('.img-with-border').hover(over, out);
$('.change-profile-pic').hover(over, out);
}());
Example fiddle(根据jfriend00的demo用JavaScript代替)
一旦用户将鼠标悬停在图像上,或者鼠标悬停在图像上,您希望它淡入淡出吗?或者你的意思是它只运行一次,当你希望它运行时*每次*鼠标悬停/拖出图像? –
你说的第二件事。每当用户将鼠标移到其上并远离它时,我都希望它一次又一次地运行。 –
@KevinReeves考虑CSS动画。 –