0

I am using jquerymobile 1.4.2. I tried with all the functions which are specified using jquery(scrollTop).But it snot working in my page. Is it possible to scroll to a specific position using css when we reload a page or when submit a button.

Tieson T.
  • 20,774
  • 6
  • 77
  • 92
user3350169
  • 209
  • 1
  • 4
  • 14
  • I tried wit this $(document).ready(function() { $('html, body').animate({scrollTop:30}, 'slow'); }); But its not working so i thought to use css – user3350169 May 14 '14 at 07:39
  • This is a http://jsbin.com/dasiguje/5/edit some times it works some time it won't,when you change the value i think you will come to in firefox – user3350169 May 14 '14 at 07:40
  • Check this one.http://stackoverflow.com/questions/8149155/animate-scrolltop-not-working-in-firefox – chandu May 14 '14 at 07:45

2 Answers2

1

Your problem is that you have the script at the top of the page. I see you wrapped it in a $(document).ready() but that alone isn't always guaranteed to work, like in your case. $(document).ready fires when the dom is loaded, the dom tells the browser that somewhere in the page there is an image, but the browser won't know the size (in pixels) of that image until it's completely loaded. This causes your issue: 1) dom starts loading 2) dom is done, $(document).ready() fires 3) the script tries to animate the scrollTop but it won't work because the page has not yet reached its complete height (because the images are not loaded), so there is no scrollbar. 4) the images load but the script has already done its job

Solutions: 1) add height and width attributes to your images 2) use $(window).load() instead of $(document).ready()

A hint for the future: if the problem is "sometimes it works, sometimes it doesn't" it's a timing problem 90% (or even more) of the times. So try to figure out what happens and when.

Jonas Grumann
  • 10,438
  • 2
  • 22
  • 40
0

No, there's no way to do that in CSS. Sorry!

Maybe, you should try for this one : jQuery.mobile.silentScroll()

Ishan Jain
  • 8,063
  • 9
  • 48
  • 75