Skip to content Skip to sidebar Skip to footer

Using To Scroll A Single Page Website

I am working on a single page website and have a problem with the tags. I would like when the user clicks a Div they get taken to a different part of the page.

Solution 1:

you can try something like this:

$('a').click(function(e) {
   e.preventDefault();
   var scr = $('#target').offset().top; // top offset of the target element
    $('html, body').animate({scrollTop: scr}, 1000)
})

DEMO


Solution 2:

Instead of trying to manipulate how the DOM elements work, wouldn't it be much easier to change your jQuery selector? http://api.jquery.com/parent-selector/


Post a Comment for "Using To Scroll A Single Page Website"