Sackling
Sackling

Reputation: 1820

jquery scroll to position on page on anchor click

I am trying to create an anchor link that when clicked will scroll down the page.

the script:

<script type="text/javascript">                         
$(document).ready(function() {
    function scrollWin(){
        $('html,body').animate({
            scrollTop: $("#scrollToHere").offset().top
        }, 800);
    }
});
</script>

the link:

<a class="icon_button" href="#"  onclick="scrollWin();" ><i class="icon-chevron-down "></i> </a>

and then the div to be scrolled to:

<div id="scrollToHere">
Scroll to here
</div>

What am I missing?

Upvotes: 2

Views: 6542

Answers (2)

bluetoft
bluetoft

Reputation: 5443

try removing the '$(document).ready(function() {' wrapper

There is no need to wrap this as you're just declaring a function.

Upvotes: 0

PaulBGD
PaulBGD

Reputation: 2084

http://jsfiddle.net/mA34T/

$('#foo').click(function () {
    $('html,body').animate({
        scrollTop: $("#scrollToHere").offset().top
    }, 800);
});

Would that fix your issue?

Upvotes: 4

Related Questions