Wie kann ich diese CSS und animieren Funktionen mehr als einmal zu stoppen, wenn der Benutzer scrollt? Derzeit feuern sie für jeden Pixel, den der Benutzer scrollt, dies verursacht Probleme!Animieren Header auf Bildlauf, feuern zu oft
<script>
var elementPosition = $('#main-wrap').offset();
var x = 0;
$(window).scroll(function(){
if($(window).scrollTop() > elementPosition.top && x != 0){
$('#dropdown-navwrap .dropdown-bar').animate({ width: "80%", overflow: "visible" }, 400);
$('#header').animate({ top: "44px" }, 400, function() { $(this).animate("padding", "0"); });
$('#hdr-logo').animate({ opacity: "0" }, 400, function() { $(this).css("display", "none"); });
$("#hdr-social").animate({ opacity: "0" }, 400, function() { $(this).css("display", "none"); });
$(".contact-box").animate({ opacity: "0" }, 400, function() {
$(this).css("display", "none"); ($('#header').css("height", "30px")).css("padding", "0px");
// logo
($('#sticky-contact').css("display", "block")).animate({opacity: 1.0});
$("a[href*=logo-sticky]").animate({opacity: 1.0});
});
} else {
$('#dropdown-navwrap .dropdown-bar').animate({ width: "100%", overflow: "visible" }, 400);
$('#hdr-logo').animate({ opacity: "1" }, 400, function() { $(this).css("display", "visible"); });
$("#hdr-social").animate({ opacity: "1" }, 400, function() { $(this).css("display", "visible"); });
$(".contact-box").animate({ opacity: "1" }, 400, function() {
$(this).css("display", "visible"); ($('#header').css("height", "95px")).css("padding", "15px 0");
// logo
($('#sticky-contact').animate({opacity: 0})).css("display", "none");
$("a[href*=logo-sticky]").animate({opacity: 0});
});
}
});
</script>
Ich empfehle Ihnen, [Wegpunkte] (http://imakewebthings.com/waypoints/) in Ihrem Fall zu verwenden. –
Ich kann keine zusätzlichen Bibliotheken installieren:/ –
Dann können Sie eine Variable setzen, die sich jedes Mal, wenn Sie die Bildlaufrichtung ändern, auf wahr/falsch ändert und verhindert, dass Ihre Funktion jedes Mal ausgelöst wird. Nur eine Idee. –