如果你真的想使用 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);
}());
小提琴示例(基于jfriend00的演示,使用 JavaScript 从这个答案代替)