Tag: scrolltop

无法使scrollTop()在Chrome和Firefox中都能正常运行

我无法使scrollTop()方法在Firefox和Chrome中都能正常工作。 我用$(‘body, html’).scrollTop(); 但是,它在Chrome中不起作用。 只有$(‘body’).scrollTop(); 适用于Chrome。 任何想法将不胜感激。 以下是我的代码。 Demo body { height: 2000px; } #light { display: block; position: fixed; top: 50%; left: 50%; margin-left: -400px; margin-top: -200px; width: 800px; height: 400px; background-color: blue; z-index:1002; overflow: auto; } $(document).ready(function() { $(window).scroll(function () { var offset = $(‘body, html’).scrollTop(); var view = $(window).height(); var total = […]

如何获得最大文档滚动值

我正在制作一些插件,我需要获得文档的最大scrollTop值。 最大scrollTop值是2001 ,但$(document).height()返回2668和$(‘body’)[0].scrollHeight给我undefined 。 如何通过javascript / jquery获取2001 ?!

使用animate.scrolltop和(target).offset()计算固定标头.top;

这应该是一个非常基本的问题,但是我早上大部分时间都在扔它,而且此时我已经接近了。 我甚至没有一点js foo – 但我找到了一个很好的评论代码块,我希望用它来动画锚链接: $(document).ready(function() { $(‘a[href*=#]’).bind(‘click’, function(e) { e.preventDefault(); //prevent the “normal” behaviour which would be a “hard” jump var target = $(this).attr(“href”); //Get the target var scrollToPosition = $(target).offset().top; // perform animated scrolling by getting top-position of target-element and set it as scroll target $(‘html, body’).stop().animate({ scrollTop: scrollToPosition}, 600, function() { location.hash […]

; Jquery:从当前屏幕位置向下缩放100px的动画页面

我需要从当前屏幕位置设置滚动动画,然后按照设定的像素数设置。 $(‘html,body’).animate({ scrollTop: $(window).position().top += 100 }); 要么? $(‘html,body’).animate({ scrollTop: ‘+=100px’ });

仅在用户滚动时调用滚动,而不是在动画()时调用滚动

我在页面上有一些链接,目的是“走到顶端”,通过将页面滚动到顶部并获得一个漂亮的动画来实现。 我注意到,有时在页面滚动时,用户会想要向下滚动,例如,但这是不可能的。 屏幕只会断断续续,但会继续制作动画,直到它到达顶部。 我想在用户尝试滚动时停止动画,因此我编写了这段代码: $(‘#gototop’).click(function() { $(‘body’).animate({scrollTop:0},3000); $(window).scroll(function () { $(‘body’).stop(); }); return false; }) 这段代码是有问题的,因为animate()计为滚动,因此它只会在停止之前移动一点点。 我也试过按键作为选项但鼠标滚动没有注册为键。 用户滚动时有没有办法调用我的滚动function,而不是动画()?

jQuery scrolltop firefox无法正常工作

这个脚本: function onscroll(){ document.getElementById(“divs”).style.top=””+$(‘body’).scrollTop()+”px”; } 小提琴: http : //jsfiddle.net/Hed2J/1/ 不适用于最新的Firefox版本! 我究竟做错了什么? :) 谢谢您的帮助! 编辑: 使用JSFiddle和完整脚本编辑:)附加到onscroll事件