English 中文(简体)
jquery scroll 顶端(x)在X大面积时没有达到目标。
原标题:jquery scrollTop(x) is not scrolling to target when x is big

我有一个问题。

I have a page that stores the current scrollTop() position in session when unloading. My goal is that when I come back to this page, the page scrolls until the last scrollTop position I had on it.

我的联合材料法典简单:

console.log( => +parseInt(scrollto)+   +parseInt($(window).scrollTop())); 
$(window).scrollTop(scrollto);
console.log( => +parseInt(scrollto)+   +parseInt($(window).scrollTop()));

摘录:

=> 2500 0
=> 2500 2500

奥基,我一页在最后的张贴上。

The issue comes with big values of scrollto variable. This is what I ve got in console :

=> 12352 0
=> 12352 7683

我拿不出为什么没有按要求的职位分配。

我甚至试图这样做:

var max_times= 10;

for(var i=0;i<max_times;i++){
console.log( => +parseInt(scrollto)+   +parseInt($(window).scrollTop()));
if (parseInt(scrollto) > parseInt($(window).scrollTop())) 
    $(window).scrollTop(scrollto);
}

结果:

=> 13450 0
=> 13450 7985
=> 13450 7985
=> 13450 7985
...
=> 13450 7985

其他信息:

  • I have the same result on Chrome and Safari.
  • The page I m talking about contains a lot of images so it takes some time to be fully loaded.

我确实希望得到任何帮助。

谢谢。

最佳回答

Ok.

我找到了一个行之有效的解决办法。

Thanks for your hints guys, the total height of the page had to be involved.

我所做的是:

var timer = setInterval(function(){
    if ((parseInt(scrollto) > parseInt($(window).scrollTop())) && (parseInt($(document).height())>parseInt(scrollto))){
       $(window).scrollTop(scrollto);
       if ($(window).scrollTop()>=scrollto)
           clearInterval(timer);    
    }
},500);

setTimeout(function(){clearInterval(timer);},10000);

我定了一个间隔,如果该网页的总高度足以使每个500米达到所要求的位置。 如果是这样的话,它就会滚动。 如果是科索沃,那么我们就清楚跨度。

如果其中没有任何一项工程,则在10个工种之后清除了该间。

再次感谢我为此提供帮助!

问题回答

@lalibi在询问图像是否带有高档,如果你要求将图像推到13450,但目前的高度低于13450px,那么,事情不会正确进行。 如果你试图把滚动时间推到所有图像装满时,它是否仍然失败? 如果你注意到,它确实如此,那么你要么必须装满图像,然后执行滚动。 顶层或固定图像高度,这样一页就知道它究竟是怎样的。





相关问题
Redirect to cache URL in Chrome browser

self.location = cache: + self.location I want to redirect from "[URL]" to "cache:[URL]". I just want this code to work in Chrome browser.

我如何更新/重载 Chrome延?

I m在4号 Chrome(目前为4.0.249.0)中开发一个延伸点,显示用户在地位酒吧中的形象。 Ive设计了一个供用户使用的备选办法网页......

Setting Opacity in CSS For Chrome

I ve tried the following: (this is actually for fancybox, as the overlay does not show in chrome/safari: $("#fancy_overlay").css({<br /> background-color : opts....

Chrome Blocking Javascript, Google Wave, Google Gadgets

Project: Developing a gadget template for Google Wave which will allow my Flash movies to interact with the Wave api. I had to adapt the existing Flex application so that it would work with ...

image height using jquery in chrome problem

$( img ).height() returns 0 in chrome, but it returns the actual height in IE and firefox. Whats the actual method to get the height of the image in chrome?

jQuery block moving

I wanna move a div block to the top, so I coded like this: CSS part: .movingPart{ margin-top:80px; } jQuery part: $(document).ready(function() { $( #btn ).click(function() { $( .movingPart )....

Table cells bad rendering with Google Chrome/Webkit

On the following code, COL1A and COL3A are not 50% height with Chrome or Webkit. It works fine with IE7 and Firefox. <table border="1"> <tr> <td height="100%">COL 1A</td>...

热门标签