【发布时间】:2020-04-28 15:05:05
【问题描述】:
这很好用:
$('.rollwrap').hover(function() {
$(this).find('.imgrollb').animate({'bottom' : 0});
}, function() {
$(this).find('.imgrollb').animate({'bottom' : '100%'});
}
);
如果rollwrap 及其内容是动态添加的,我需要委托该功能,但这不起作用:
$(document).on('hover', '.rollwrap', function(){
$(this).find('.imgrollb').animate({'bottom': 0});
}, function(){
$(this).find('.imgrollb').animate({'bottom': '100%'});
}
);
如何获得与动态内容相同的功能?
【问题讨论】:
-
hover不是一个事件,它是两个相关事件的快捷方式。.on()不允许你提供多个处理函数。 -
@Barmar 我明白了,谢谢,但有什么合乎逻辑的理由为什么允许在静态内容而不是动态内容上使用快捷方式?
-
静态不允许。
$(".rollwrap").on("hover", function() { ...}, function() {...})也不起作用。
标签: javascript jquery