Rails4: “scrollTop” doesn't work every other click

China☆狼群 提交于 2019-12-11 22:34:28

问题


scrollTop doesn't work every other click (every second click).

I use will_paginate at the bottom of the page.

When I click on a link, the page is refreshed and the display position is at the bottom of the page.
Then I click on a link to another page, the page is refreshed and the display position is at the top of the page as I expect.

For example,
When I click the link to page 2, the page 2 is displayed but the display position remains at the bottom.
When I click the link to page 5, the page 5 is displayed and the display position is at the top as I expect.
When I click the link to page 6, the page 6 is displayed but the display position remains at the bottom.
When I click the link to page 8, the page 8 is displayed and the display position is at the top as I expect.
...

I have tried the followings, I had the same result.

\assets\javascripts\calendars.js.coffee

$('html, body').animate({ scrollTop: 0 }, 'slow')

$('body').animate({ scrollTop: 0 }, 'slow')

$('html, body').scrollTop()

$(document).scrollTop()

$(window).scrollTop()

$(window).scrollTop(0)

\views\calendars\index.html.erb

...
<%= will_paginate @calendar %>
...

How should I edit my code?

来源:https://stackoverflow.com/questions/26447948/rails4-scrolltop-doesnt-work-every-other-click

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!