I have a small part of jQuery designed to smooth my title, resize it and then snap to the side of the screen. Everything works separately from one part, the function of "switching" the height is activated every time the user scrolls, which causes irritation.
Is there a way to detect scrolling only once or switch only once?
$(window).scroll(function () { var width = $(document).width() - 205; var height = $(document).height(); $('#me').animate({ marginLeft: width, width: '22px', height: 'toggle', borderLeftWidth: "10px", borderRightWidth: "10px" }, 1000, function() { $("#me:first").css("margin-top","-90px"); var div = $('#me'); $('#me h1').css("font-size","30px"); var start = $(div).offset().top; $(div).css("height", height); $.event.add(window, "scroll", function() { var p = $(window).scrollTop(); $(div).css('position',((p)>start) ? 'fixed' : 'static'); $(div).css('top',((p)>start) ? '0px' : ''); }); }); });
source share