inuyaksa / jquery.nicescroll

nicescroll plugin for jquery - scrollbars like iphone/ipad
https://nicescroll.areaaperta.com/
3.6k stars 1.66k forks source link

scroll to top #5

Closed ghost closed 13 years ago

ghost commented 13 years ago

Hi,

I'm really loving your plugin, but I have a question. The scrollbar works perfectly in iframes, but when you click a link on the page, the scrollbar preserves its location even on the new page. I need it to scroll to the top, but I can't figure out how to do it.

Any help would be greatly appreciated.

Yvonne

inuyaksa commented 13 years ago

It needs some investigation, I write you soon.

inuyaksa commented 13 years ago

Do you have an example to see?

inuyaksa commented 13 years ago

I'd played with iframes. I have create two demo pages, so you can find usefull advices. http://www.areaaperta.com/nicescroll/test/iframe.html http://www.areaaperta.com/nicescroll/test/iframe2.html

You find a donwload to new beta version, with a more robust iframe support.

Let me know if you find the solution.

ghost commented 13 years ago

Hi, I will test this and get back to you! Thanks for your help.

ghost commented 13 years ago

In your second demo, the one with the wrapper, it scrolls to top, but as you can also see in your demo, off-site links will show the regular scrollbar and it doesn't calculate the height right, so there's extra whitespace at the bottom of the page. Also, a scrollbar is visible, even though the page doesn't need scrolling.

Thanks again!

inuyaksa commented 13 years ago

The demo pages use actual version. Have you test the beta version? (you find link in the first iframe page)

ghost commented 13 years ago

I have tested, but it didn't make a difference.

inuyaksa commented 13 years ago

Do you have an example page to view the problem? So I can help you.

ghost commented 13 years ago

I have the exact same issues as on this page: http://www.areaaperta.com/nicescroll/test/iframe2.html Sorry, don't have an example I can actually show at the moment. But the issues are exactly the same.

Off-site links like http://fsf.org/ will show the regular scrollbar and it doesn't calculate the height right, so there's extra whitespace at the bottom of the page.

I have tested this in Firefox 7 and Chrome.

inuyaksa commented 13 years ago

That's the problem! Off-site sites can't work. Cross-domain policy of major browser don't permits nicescroll script to hide scrollbar and gain the height of iframe content. There is same tricks to achieve this info but is necessary to modify the off-site page html too. (look this http://www.cakemail.com/the-iframe-cross-domain-policy-problem/)

With same-domain page, script can resize iframe automatically.

If you can obtain height of content (as in the example link), you can resize height of iframe then recall $("nameofdiv").getNiceScroll().onResize(); (in the iframe2 page you can find more complete code, but iframe2 works only for same-domain pages)

ghost commented 13 years ago

It seems to be working for now. Much appreciated.

One more question: is it possible to hide the scrollbar when no scrolling is needed? i.e. the page is not long enough?

inuyaksa commented 13 years ago

yes, you'll do in the next version. (see preview of features on the wiki)