如何在底部显示 100px 时在滚动时触发 jquery 函数
how to trigger jquery function on scroll when it shows 100px fro the bottom
>我的网站上有"有趣的事实"计数器,还有一个jQuery函数,可以动画计数有趣的事实中的数字div.现在,它会在页面加载时触发。我想在用户向下滚动到它时启动它。例如,当div 从屏幕底部出现 100px 时。
这是我的jQuery函数,它在页面加载时开始计数:
(function($) {
"use strict";
function count($this){
var current = parseInt($this.html(), 10);
current = current + 10; /* Where 50 is increment */
$this.html(++current);
if(current > $this.data('count')){
$this.html($this.data('count'));
} else {
setTimeout(function(){count($this)}, 50);
}
}
$(".stat-count").each(function() {
$(this).data('count', parseInt($(this).html(), 10));
$(this).html('0');
count($(this));
});
})(jQuery);
这是我尝试在用户向下滚动到它时使其工作:
(function($) {
"use strict";
function count($this){
var current = parseInt($this.html(), 10);
current = current + 10; /* Where 50 is increment */
$this.html(++current);
if(current > $this.data('count')){
$this.html($this.data('count'));
} else {
setTimeout(function(){count($this)}, 50);
}
}
$(window).scroll(function() {
$(".stat-count").each(function() {
var imagePos = $(this).offset().top;
var topOfWindow = $(window).scrollTop();
if (imagePos < topOfWindow+400) {
$(this).data('count', parseInt($(this).html(), 10));
$(this).html('0');
count($(this));
}
}
}
})(jQuery);
谢谢!:)
可能是
这样的:
$(window).on('scroll', function(event) {
if(document.body.offsetHeight - event.pageY <= 100 ) {
//onscoll effect
}
}
相关文章:
- 是否有一个JS/jQuery函数可以获取某个类的每个元素的ID
- 如何在JQuery函数中定义一个值,然后调用另一个函数并使用该值
- 如何从jquery函数返回变量
- 如何将具有文本类型值的var放入jQuery函数中
- Jquery函数在错误的时间提交
- 锚链接无法使用.slideUp jquery函数
- 重新分解jQuery函数
- 如何在视图模型contet更新更新上调用Jquery函数
- 如何向这个javascript/jquery函数添加参数
- 添加类来触发jquery函数
- 更改智能表中的页面将停止JQuery函数的工作
- 使用每500ms运行一次的jquery函数是个好主意吗
- jQuery函数不能只在一个页面上工作
- 如何将jquery函数链接到vanilla选择器
- 仅在小型设备上调用jQuery函数
- 如何将jquery函数仅应用于大屏幕
- 奇怪的jquery函数行为
- Backbone listenTo不将jquery函数作为处理程序进行激发
- 在jquery函数内部设置来自jquery函数的var;t运行
- 从Jquery函数中获取一个变量