gpt4 book ai didi

javascript - 标准功能工作正常,但如果委派 - 则不行

转载 作者:行者123 更新时间:2023-12-01 08:33:28 24 4
gpt4 key购买 nike

这工作正常:

$('.rollwrap').hover(function() {
$(this).find('.imgrollb').animate({'bottom' : 0});
}, function() {
$(this).find('.imgrollb').animate({'bottom' : '100%'});
}
);

如果rollwrap并且其内容是动态添加的我需要委托(delegate)该函数,但这不起作用:

$(document).on('hover', '.rollwrap', function(){
$(this).find('.imgrollb').animate({'bottom': 0});
}, function(){
$(this).find('.imgrollb').animate({'bottom': '100%'});
}
);

如何获得与动态内容相同的功能?

最佳答案

传递给 .hover 的两个函数是 mouseenter 和 mouseleave 处理程序,因此您可以使用这些事件进行委托(delegate):

$(document).on('mouseenter', '.rollwrap', function(){
$(this).find('.imgrollb').animate({'bottom': 0});
});
$(document).on('mouseleave', '.rollwrap', function(){
$(this).find('.imgrollb').animate({'bottom': '100%'});
});

关于javascript - 标准功能工作正常,但如果委派 - 则不行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59690568/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com