2016-10-07 6 views
0

Ich versuche, die Scroll To Top-Taste erscheinen zu lassen, sobald der Benutzer nach unten scrollte, anstatt dass er immer vorhanden ist, auch wenn er oben ist. Schnelle Notiz, ich habe kaum Erfahrung mit JS, also habe ich keine Ahnung was ich mache.Scroll-to-Top-Taste auf einer mobilen Website

Auf jeden Fall hier ist die Seite, die ich auf einen Fehler habe: http://www.m.evans-carpentry.com/gallery/projects/

<script> 
 
\t \t \t $(function() { 
 
\t \t \t \t var $elem = $('#content'); 
 
\t \t \t \t 
 
\t \t \t \t $('#nav_up').fadeIn('slow'); 
 
\t \t \t \t $('#nav_down').fadeIn('slow'); 
 
\t \t \t \t 
 
\t \t \t \t $(window).bind('scrollstart', function(){ 
 
\t \t \t \t \t $('#nav_up,#nav_down').stop().animate({'opacity':'0.2'}); 
 
\t \t \t \t }); 
 
\t \t \t \t $(window).bind('scrollstop', function(){ 
 
\t \t \t \t \t $('#nav_up,#nav_down').stop().animate({'opacity':'1'}); 
 
\t \t \t \t }); 
 
\t \t \t \t 
 
\t \t \t \t $('#nav_down').click(
 
\t \t \t \t \t function (e) { 
 
\t \t \t \t \t \t $('html, body').animate({scrollTop: $elem.height()}, 800); 
 
\t \t \t \t \t } 
 
\t \t \t \t); 
 
\t \t \t \t $('#nav_up').click(
 
\t \t \t \t \t function (e) { 
 
\t \t \t \t \t \t $('html, body').animate({scrollTop: '0px'}, 800); 
 
\t \t \t \t \t } 
 
\t \t \t \t); 
 
      }); 
 
     </script>

Dank!

+0

Teilen Sie Ihren vollständigen Code, es kann hoffnungsvoll sein. –

+1

Ihre jquery-Datei wird nicht ordnungsgemäß geladen. Vielleicht möchten Sie das zuerst überprüfen. – Brian

+0

Devtools ist ein großartiges Instrument zum Debuggen. Sie haben einige Fehler in Ihrem JS, um es zuerst zu korrigieren. ZB '$ ist nicht definiert' –

Antwort

0

Sie rufen jquery früheren Ankündigungen von jquery on line 30

<script>$('#nav Li: has (ul)').doubleTapToGo();</script> 

Einsatz dieser Zeile nach dem Aufruf jquery

0

Ihr Code zu komplex ist, versuchen Sie dies:

$(document).ready(function(){ 
 
     //Check to see if the window is top if not then display button 
 
     $(window).scroll(function(){ 
 
      if ($(this).scrollTop() > 100) { 
 
       $('.scrollToTop').fadeIn(); 
 
      } else { 
 
       $('.scrollToTop').fadeOut(); 
 
      } 
 
     }); 
 
     //Click event to scroll to top 
 
     $('.scrollToTop').click(function(){ 
 
      $('html, body').animate({scrollTop : 0},800); 
 
      return false; 
 
     }); 
 
    });

".scro llToTop "ist die zu klickende Sache, die zurück zum Anfang der Seite scrollt.

Verwandte Themen