M
M
Michael2015-12-31 21:57:35
JavaScript
Michael, 2015-12-31 21:57:35

Why does it work in chrome but not in firefox?

<script>
  $(document).ready(function() {
  $('a[href^="#"]').click(function(){
  var el = $(this).attr('href');
  $('body').animate({
  scrollTop: $(el).offset().top}, 700);
  return false;
  });
  });
</script>

view anchors Why does it work in chrome, but not in firefox, either through a script or through standard anchors? I understand the script in firefox works, but incorrectly. <a id="1" name="1"></a>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
afishr, 2015-01-01
@Madfisht3

For Firefox you need to use

$('html').animate({
         scrollTop: $(el).offset().top}, 700);
});

But this option does not seem to be suitable for Chrome, so you need to use both with bodyand withhtml

Z
zwoc, 2015-12-31
@zwoc

Found a similar question:
stackoverflow.com/questions/3163615/how-to-scroll-...
There, the solution to the problem was solved by wrapping the scrollTop with single quotes, i.e.

$('body').animate({
    'scrollTop' : $(el).offset().top}, 700);
  return false;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question