Jquery scroll to top of div not working
This question is not particularly a Joomla question but a jQuery/HTML one, so I am not sure this should be included and answered here in JSE as a question. Probably this could get much more answers at Stack Overflow. As I understood your issue more, you are just looking for an additional jQuery/Javascript snippet, something like this:
Show This snippet is just checking the window width and we just target landscape laptops, desktop, tablets at high res devices. If someone clicks on the The combined, cleaner jQuery snippet would look something like this:
in case it matters for you, you can change this line in the above code, just to keep the nicer top-margin of the content on mobile views:
only side note: The jQuery code you provided in your question must be cleaned up much more from the ❮ jQuery HTML/CSS Methods ExampleReturn the vertical scrollbar position for a element:
$("button").click(function(){ alert($("div").scrollTop()); }); Try it Yourself » Definition and UsageThe scrollTop() method sets or returns the vertical scrollbar position for the selected elements. Tip: When the scrollbar is on the top, the position is 0. When used to return the position: This method returns the vertical position of the scrollbar for the FIRST matched element. When used to set the position: This method sets the vertical position of the scrollbar for ALL matched elements. SyntaxReturn vertical scrollbar position: Set vertical scrollbar position: $(selector).scrollTop(position) Parameter Description position Specifies the vertical scrollbar position in pixels Try it Yourself - ExamplesSet the vertical scrollbar position How to set the vertical scrollbar position for an element. Toggle between classes on different scroll positions How to toggle between classes on different scroll positions. Add smooth scrolling to page anchors Using animate() together with scrollTop() to add smooth scrolling to links. ❮ jQuery HTML/CSS Methods ★ +1 I have used a scrollTop function in jQuery for navigating to top, but strangely 'the smooth animated scroll' stopped working in Safari and Chrome (scrolling without smooth animation) after I made some changes. But it is still working smoothly in Firefox. What could be wrong? Here is the jQuery function I used, jQuery: $('a gotop').click(function() {$("html").animate({ scrollTop: 0 }, "slow");
//alert('Animation complete.');
//return false;
|