Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It's not a Chrome bug. Your <a href="http://jsfiddle.net/uKcQG" rel="nofollow">original code</a> contains some strange stuffs. </p> <ul> <li>You don't have any elements with <code>scroll-top</code> class, which should be shown when scrolling down, and which the user could click on to scroll to the top. </li> <li>You don't have any elements with <code>top</code> or <code>bottom</code> id like in the other one.</li> <li>You left out some <a href="http://antaw.de/RM/stylesheets/scroll.css" rel="nofollow">needed CSS codes</a> from the JSFiddle-code which you do have in the other working example.</li> <li><p>But one of the <strong>most important</strong> errors: <code>target</code> variable is undefined in your JavaScript code, and you inspect its equality with "#top" string. This leads to a ReferenceError exception. I think you wanted to inspect whether the click event's target element's id is equal to the <code>"#top"</code> string. For this, you should declare e.g. the <code>event</code> argument in the event handler, and use <code>event.target.id</code>. So instead of this:</p> <pre><code>$('.scroll').click(function(){ $('html, body').animate({ scrollTop: $(this.id).offset().top }, 500); setTimeout("$('.scroll-top').fadeIn();",510 ); if (target == "#top"){$('.scroll-top').hide() ;} }); </code></pre> <p>You should use this code:</p> <pre><code>$('.scroll').click(function(event) { // declaring event variable as an argument $('html, body').animate({ scrollTop: $(this.id).offset().top }, 500); // inspecting the id of the click event's target element if (event.target.id == "#top") { $('.scroll-top').hide(); } else { setTimeout(function () { $('.scroll-top').fadeIn(); }, 510); } }); </code></pre></li> </ul> <p>I modified your <a href="http://jsfiddle.net/uKcQG" rel="nofollow">original code</a>, uncommenting very much unneeded stuffs, but there are still many left:</p> <p><a href="http://jsfiddle.net/uKcQG/3/" rel="nofollow">http://jsfiddle.net/uKcQG/3/</a></p> <p>It's still a little buggy, but now the scrolling seems to work correctly.</p> <p>But as I suggested in my comment, <strong>you should definitely use Ariel Flesler's <em>jQuery scrollTo plugin</em> for this task: <a href="http://demos.flesler.com/jquery/scrollTo/" rel="nofollow">http://demos.flesler.com/jquery/scrollTo/</a></strong></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload