老师帮我看下为什么触发不到监听的事件
<div class="consumer">
<div class="container">
<div class="consumer-group">
<span class="consumer-group-title">消费者保障</span>
<div class="consumer-group-detail">
<a href="###" target="_blank" class="link">保障范围</a>
<a href="###" target="_blank" class="link">保障范围</a>
<a href="###" target="_blank" class="link">保障范围</a>
<a href="###" target="_blank" class="link">保障范围</a>
</div>
</div
><div class="consumer-group">
<span class="consumer-group-title">消费者保障</span>
<div class="consumer-group-detail">
<a href="###" target="_blank" class="link">保障范围</a>
<a href="###" target="_blank" class="link">保障范围</a>
<a href="###" target="_blank" class="link">保障范围</a>
<a href="###" target="_blank" class="link">保障范围</a>
</div>
</div
><div class="consumer-group">
<span class="consumer-group-title">消费者保障</span>
<div class="consumer-group-detail">
<a href="###" target="_blank">保障范围</a>
<a href="###" target="_blank">保障范围</a>
<a href="###" target="_blank">保障范围</a>
<a href="###" target="_blank">保障范围</a>
</div>
</div
><div class="consumer-group">
<span class="consumer-group-title">消费者保障</span>
<div class="consumer-group-detail">
<a href="###" target="_blank">保障范围</a>
<a href="###" target="_blank">保障范围</a>
<a href="###" target="_blank">保障范围</a>
<a href="###" target="_blank">保障范围</a>
</div>
</div>
</div>
</div>
//consumer
var consumer={};
consumer.$doc=$(document);
consumer.$consumer=$(".consumer");
//是否出现在可视区域
consumer.isVisible = function ($elem) {
//页面可视区域的高度加页面滚动高度大于元素上边沿距离顶部高度时,元素位于可视区域之外---下边界
//页面滚动高度小于元素自身高度以及页面滚动高度之和----上边界
return (floor.$win.height() + floor.$win.scrollTop() > $elem.offset().top);
}
consumer.timeToShow = function ($elem) {
$elem.each(function (index, ele) {
if (consumer.isVisible($(ele))) {
console.log(1)
consumer.$consumer.trigger("consumer-show");
}
})
}
consumer.timeToShow(consumer.$consumer);
consumer.$consumer.on('consumer-show',function (e) {
console.log(e.type)
console.log(1)
})
// console.log(consumer.isVisible(consumer.$consumer));
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星