Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/362.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 滚动停止百分比时触发_Javascript_Jquery - Fatal编程技术网

Javascript 滚动停止百分比时触发

Javascript 滚动停止百分比时触发,javascript,jquery,Javascript,Jquery,我需要触发当用户停止滚动,并提醒一些消息。但我需要按百分比触发它 例如,我想提醒用户一些消息,如果他滚动,但当他停止滚动,如果他滚动超过80%的窗口 我有一段代码,当srcoll停止时触发,但不知道如何使用scroll percen完成此工作: $.fn.scrollStopped = function(callback) { $(this).scroll(function(){ var self = this, $this = $(self);

我需要触发当用户停止滚动,并提醒一些消息。但我需要按百分比触发它

例如,我想提醒用户一些消息,如果他滚动,但当他停止滚动,如果他滚动超过80%的窗口

我有一段代码,当srcoll停止时触发,但不知道如何使用scroll percen完成此工作:

$.fn.scrollStopped = function(callback) {           
    $(this).scroll(function(){
        var self = this, $this = $(self);
        if ($this.data('scrollTimeout')) {
            clearTimeout($this.data('scrollTimeout'));
        }
        $this.data('scrollTimeout', setTimeout(callback,250,self));
    });
};

jQuery(window).scrollStopped(function(){
    alert('stopped');
});
演示:

演示:

演示:

演示:


您可以计算文档和窗口的高度,然后将其与滚动条的当前垂直位置进行比较:

$.fn.scrollStopped = function(callback) {           
    $(this).scroll(function(){
        var self = this, $this = $(self);
        if ($this.data('scrollTimeout')) {
            clearTimeout($this.data('scrollTimeout'));
        }
        $this.data('scrollTimeout', setTimeout(callback,250,self));
    });
};

jQuery(window).scrollStopped(function(){
    console.log(jQuery(window).scrollTop());
    if($(window).scrollTop() > ($(document).height() - $(window).height())*0.8){
       alert('You have scrolled more than 80%');
    }

});

。您可能想阅读有关这两个函数的更多详细信息;和。

您可以计算文档和窗口的高度,然后将其与滚动条的当前垂直位置进行比较:

$.fn.scrollStopped = function(callback) {           
    $(this).scroll(function(){
        var self = this, $this = $(self);
        if ($this.data('scrollTimeout')) {
            clearTimeout($this.data('scrollTimeout'));
        }
        $this.data('scrollTimeout', setTimeout(callback,250,self));
    });
};

jQuery(window).scrollStopped(function(){
    console.log(jQuery(window).scrollTop());
    if($(window).scrollTop() > ($(document).height() - $(window).height())*0.8){
       alert('You have scrolled more than 80%');
    }

});

。您可能想阅读有关这两个函数的更多详细信息;和。

您可以计算文档和窗口的高度,然后将其与滚动条的当前垂直位置进行比较:

$.fn.scrollStopped = function(callback) {           
    $(this).scroll(function(){
        var self = this, $this = $(self);
        if ($this.data('scrollTimeout')) {
            clearTimeout($this.data('scrollTimeout'));
        }
        $this.data('scrollTimeout', setTimeout(callback,250,self));
    });
};

jQuery(window).scrollStopped(function(){
    console.log(jQuery(window).scrollTop());
    if($(window).scrollTop() > ($(document).height() - $(window).height())*0.8){
       alert('You have scrolled more than 80%');
    }

});

。您可能想阅读有关这两个函数的更多详细信息;和。

您可以计算文档和窗口的高度,然后将其与滚动条的当前垂直位置进行比较:

$.fn.scrollStopped = function(callback) {           
    $(this).scroll(function(){
        var self = this, $this = $(self);
        if ($this.data('scrollTimeout')) {
            clearTimeout($this.data('scrollTimeout'));
        }
        $this.data('scrollTimeout', setTimeout(callback,250,self));
    });
};

jQuery(window).scrollStopped(function(){
    console.log(jQuery(window).scrollTop());
    if($(window).scrollTop() > ($(document).height() - $(window).height())*0.8){
       alert('You have scrolled more than 80%');
    }

});

。您可能想阅读有关这两个函数的更多详细信息;和。

我猜您必须计算到窗口高度的滚动距离我猜您必须计算到窗口高度的滚动距离我猜您必须计算到窗口高度的滚动距离我猜您必须计算到窗口高度的滚动距离我猜您必须计算到窗口高度的滚动距离