0

I have following code to scroll the desired section targeted by attr

$('html, body').animate({
  scrollTop: $( attr).offset().top -300
}, 500)

Page successfully scrolls to that position in desktop but not in iPad. I will have to update the value from 300 to suitable values for iPad. How can i make it dynamic so that it works correctly in all the devices?

rrk
  • 15,677
  • 4
  • 29
  • 45
Ninja
  • 428
  • 4
  • 17

2 Answers2

0
   $("html, body").animate({
    scrollTop: $('#tagID').offset().top 
}, 2000);

Try this... add your target ID or Class.

Myco Claro
  • 475
  • 2
  • 14
  • I need to show my targetted id in the middle of screen or to the defined position thats why i used 300. But in ipad it shows at desired position of mine when value is 200.. how to make this dynamic? – Ninja Sep 19 '17 at 06:07
0

pls refer

http://jsfiddle.net/lollero/ZVdRt/

jQuery jump or scroll to certain position, div or target on the page from button onclick

for example.

$("body, html").animate({ 
    scrollTop: $( $(this).attr('href') ).offset().top 
}, 600)
ajith mohan
  • 527
  • 4
  • 16
  • This way takes to that element but i want to show at the position defined by $( attr).offset().top **-300** – Ninja Sep 19 '17 at 06:09