我搜索了很多这些天,但我没有设法解决我的问题。滚动到特定的div或id后触发事件
我有下面的脚本是一个简单的计数器,从0开始计算一些统计数据。它开始于我的页面加载时。我想在我滚动到特定的div或id时触发此事件,但仅触发一次。我用.one()方法等看了很多例子,但我没有找到合适的解决方案。
这是我的脚本。
<script type="text/javascript">
$.fn.jQuerySimpleCounter = function(options) {
var settings = $.extend({
start: 0,
end: 100,
easing: 'swing',
duration: 500,
complete: ''
}, options);
var thisElement = $(this);
$({count: settings.start}).animate({count: settings.end}, {
duration: settings.duration,
easing: settings.easing,
step: function() {
var mathCount = Math.ceil(this.count);
thisElement.text(mathCount);
},
complete: settings.complete
});
};
$('.number1').jQuerySimpleCounter({end: 14,duration: 2899});
$('.number2').jQuerySimpleCounter({end: 350,duration: 3300});
$('.number3').jQuerySimpleCounter({end: 450,duration: 4000});
$('.number4').jQuerySimpleCounter({end: 7,duration: 2500});
</script>
那么我应该添加什么来触发它达到某个div或id后...?
也许这会帮助你.. http://stackoverflow.com/questions/1225102/jquery-event-to-trigger-action-when-a-div-is-made-visible –
看看这个插件http://imakewebthings.com/waypoints/guides/getting-started/ –