2017-02-23 5 views
0

Verwaltet, um eine feste Schaltfläche hinzufügen, wenn ich die Seite nach unten blättern, aber ich möchte dies bis zu einem bestimmten Punkt (wenn das Nav aus nicht sichtbar ist) ausgeblendet werden.Feste Schaltfläche auf Bildlauf

Ich werde dir meinen Code bis jetzt zeigen und ihr könnt mir hoffentlich zeigen, wo ich falsch gelaufen bin.

CSS

.fixed-btn { 
    position: fixed; 
    top: 60px; 
    right: 80px; 
    height: 100px; 
    z-index: 999; 
    display: none; 
} 

HTML

<div class="fixed-btn"> 
    <a onclick="fatsomaEventsWidget.showEvent('akvmo30l')" href="#event_id=akvmo30l" class="btn btn--white-bg" href="#" role="button">Get Wristbands</a> 
</div> 

JS

var wristbands = $(".fixed-btn"); 

wristbands.on("scroll", function (e) { 

    if (this.scrollTop > 900) { 
     wristbands.css('display: block;'); 
    } else { 
     wristbands.css('display: none;'); 
    } 

}); 
+0

Was das aktuelle Verhalten des Codes ist? – Kornflexx

+0

Javascript ist nicht funktionsfähig, wenn ich also das Anzeigeattribut von CSS entferne, funktioniert es wie beabsichtigt. Ich brauche nur Hilfe, um die Schaltfläche vor einem bestimmten Bildlaufpunkt auf der Seite zu verbergen. –

Antwort

0

versuchen, diese

  $(window).scroll(function(){ 
        if ($(this).scrollTop() > 900) { 
         $(".fixed-btn").fadeIn(); 
        } else { 
         $(".fixed-btn").fadeOut(); 
        } 
      }); 

EDIT:

entfernen display:none von css

0

Zunächst einmal können Sie nicht mehr als $ bewegen ("fixed-btn."), Wenn es versteckt ist. Zweitens wristbands.css('display: block;'); nicht korrekt ist, haben Sie wristbands.css('display','block');

Versuchen Sie, so etwas zu tun.

$(window).scroll(function() { 
    if($(document).scrollTop() > 900){ 
     $(".fixed-btn").css("display", "block"); 
     // do whatever you want 
    } 
}); 

DEMO

0

$(document).scroll(function() { 
 
     var y = $(this).scrollTop(); 
 
     if (y > 85) { 
 
      $('.lead-bar').addClass("display"); 
 
     } else { 
 
      $('.lead-bar').removeClass("display"); 
 
     } 
 
    });
.para{margin-top:160px} 
 
.lead-bar{position:absolute;top:0;display:none} 
 
.lead-bar.display{display:block} 
 
.lead-bar.display a{position:fixed;top:15px;right:15px;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.2.3/jquery.min.js"></script> 
 
<div class="lead-bar"> 
 
    <a href="#" role="button">Get Wristbands</a> 
 
</div> 
 
<p class="para">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>