Reputation:
I have a script that works just fine in chrome but not in Firefox and I have no idea why this is. The script is suppose to scroll down to an id from an anchor but does nothing in Firefox.
Example how I use the script below!
<nav>
<ul>
<li><a class="scroll" target="home">Home</a></li>
</ul>
</nav>
<div id="home">
.....
</div>
<script>
$('.scroll').click(function() {
$(document).animate({
scrollTop: eval($('#' + $(this).attr('target')).offset().top - 70)
}, 1000);
});
</script>
Upvotes: 3
Views: 673
Reputation: 92923
Change $(document).animate
to $('html,body').animate
.
http://jsfiddle.net/mblase75/vL79H/
That said, I would tighten up your code a bit by using HTML-standard hash links, in case JavaScript is disabled or not working:
<li><a class="scroll" href="#home">Home</a></li>
Then modify the code to accommodate it and remove the unnecessary eval
statement:
$('.scroll').click(function (e) {
e.preventDefault();
$('html,body').animate({
scrollTop: $($(this).attr('href')).offset().top - 70
}, 1000);
});
Upvotes: 6