Sunday, May 12, 2024
 Popular · Latest · Hot · Upcoming
136
rated 0 times [  139] [ 3]  / answers: 1 / hits: 122683  / 12 Years ago, sun, march 18, 2012, 12:00:00

Lately im trying to use jquery more often and right now im having some problem i'd like to solve with jquery hope u could help me.



I have some web page that includes some anchor tag (lets say the anchor is located in the middle of the page) and on the event onload i want the page to start on that certain anchor tag location meaning the page will be scrolled automaticaly to a certain location.



That was my previous solution (which is quite ugly since it adds #i to my url)



window.onload = window.location.hash = 'i';


Anyway could u tell me how can i do it with jquery?



notice: i don't want the user to feel any slide or effect while getting to this location


More From » jquery

 Answers
2

Use the following simple example



function scrollToElement(ele) {
$(window).scrollTop(ele.offset().top).scrollLeft(ele.offset().left);
}


where ele is your element (jQuery) .. for example : scrollToElement($('#myid'));


[#86769] Friday, March 16, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
harleyaleenag

Total Points: 678
Total Questions: 121
Total Answers: 105

Location: Papua New Guinea
Member since Thu, Jul 9, 2020
4 Years ago
harleyaleenag questions
Thu, May 5, 22, 00:00, 2 Years ago
Wed, Aug 19, 20, 00:00, 4 Years ago
;