jQuery - Smooth scroll only working to top - need it to work to bottom aswell

Andreas 'aNdy' Berggreen

im trying to use a smooth scroll for my href elements. The only problem is that i can only get it to do it upwards.

The live site is here

If you click on the box "Webdesign" it should do a smooth scrool down to the .content. The same thing if you hit the button of the bottom of that content it should scroll up to the top again smoooth(That works fine) - Its downwards to the start of the "webdesign" content it doesnt work.

script used in the bottom of the site:

<script type="text/javascript">
$("a[href^='#']").click(function(){ 
var contentPosTop = $('.content').position().top;

$('html, body').stop().animate({
    scrollTop: contentPosTop
}, 1500);
});
</script>

Any ideas?

Ricardo Nuñez

In Firebug it says that contentPosTop is 0. I don't know why, but I didn't look into it because I don't think you need to calculate that value. You will scroll down the same distance in any option (the logo + the menu height ). Try something like 660 and see if it works. At least in my test it did.

$("a[href^='#']").click(function(){ 
$('html, body').stop().animate({ scrollTop: 660 }, 1500);
});

EDIT: To go back to the top

   $('#starter-template').click(function() {
    $('html, body').stop().animate({ scrollTop: 0}, 1500);
    });

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

jquery datatables scroll to top when pages clicked from bottom

From Dev

Smooth scroll no anchor only jQuery

From Dev

jQuery - Smooth scroll only working to top - need it to work to bottom aswell

From Dev

Scroll to Top and Scroll to Bottom in Jquery

From Dev

Scroll to Bottom in Jquery is not working properly

From Dev

jQuery Smooth Scroll Offset

From Dev

jQuery scroll only detecting scroll at very top of the page and bottom?

From Dev

JS for smooth scroll to the bottom of the page

From Dev

jQuery smooth scroll positioning doesn't work

From Dev

Scroll top, then bottom, then top, then bottom

From Dev

how to scroll top and bottom

From Dev

Material Design Lite and jQuery, smooth scroll not working

From Dev

JS Smooth scrolling, scroll to bottom of final / bottom div instead of top

From Dev

Choppy jquery smooth scroll

From Dev

Scroll to Bottom in Jquery is not working properly

From Dev

Scroll to Top and Scroll to Bottom in Jquery

From Dev

Smooth scroll not working

From Dev

jQuery .css() top & bottom not working

From Dev

JS for smooth scroll to the bottom of the page

From Dev

Jquery Smooth Scroll only working internally

From Dev

Smooth scroll to div not working?

From Dev

Links jump to top and bottom but smooth scrolling doesn't work

From Dev

jquery scroll bottom to top, prepand and ajax

From Dev

Scroll bottom of browser viewport to top of element (jQuery)

From Dev

Jquery Smooth Scroll not working, Tried almost everything

From Dev

Need Jquery for button mouseover scroll to top

From Dev

Smooth scroll to top not working

From Dev

Javascript scroll to the top and scroll to the bottom

From Dev

Jquery Smooth Scroll Using Offset.top

Related Related

HotTag

Archive