我想检测滚动在一个div内的div与position:fixed;
。 这个div与位置固定属性是由JavaScript所以我附上事件处理这样如何检测位置固定时在div中滚动
$(document).on('scroll', '.scroll_div', function(){
console.log("scrolled!");
});
但它不工作被添加到DOM。
我想检测滚动在一个div内的div与position:fixed;
。 这个div与位置固定属性是由JavaScript所以我附上事件处理这样如何检测位置固定时在div中滚动
$(document).on('scroll', '.scroll_div', function(){
console.log("scrolled!");
});
但它不工作被添加到DOM。
尝试使用,每次后,当您添加新的.scroll_div
元素到DOM。
$('.scroll_div').off('scroll').on('scroll', function(){
console.log("scrolled!");
});
它完美的作品,但你可以告诉我你在这里做了什么。 – 2015-03-02 18:14:39
禁用上次绑定的所有绑定'滚动'事件并绑定新事件。 $(document).on('event','element')与$('element')。on('event')不一样,因为第一个例子将来会添加元素,但在这种情况下$(document).on binding不支持'scroll'事件。因此,每当您向DOM添加新的'.scroll_div'元素时,您都会使用此代码。 – 2015-03-02 18:16:17
感谢您的解释@Mateusz Mania – 2015-03-07 00:56:30
能否请您的HTML和CSS增加的问题。 http://jsfiddle.net中的一个工作示例也不会伤害任何一个。 – 2015-03-02 17:48:14
我为它做了一个jsfiddle。 [链接](http://jsfiddle.net/vtuuwL3a/),请检查它。 – 2015-03-02 18:05:35