Reputation: 1820
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
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
Reputation: 2084
$('#foo').click(function () {
$('html,body').animate({
scrollTop: $("#scrollToHere").offset().top
}, 800);
});
Would that fix your issue?
Upvotes: 4