1

I want to stop animation of showing 'black header'.

If you scroll couple of times fast you'll notice that animation is triggered and the black header will "flash"

$(window).scroll(function() {
    if ($(window).scrollTop() > 200) {  
        $(".prim").fadeIn(250);
    }
    else {
        $(".prim").fadeOut(250);
    }
});

//Sticky bar responsive fix
$(window).resize(function(){
    var width = $(window).width();

    if( width > 1024 && $(window).scrollTop() > 190 ){
        $(".prim").fadeIn(250);
    }
    else{
        $(".prim").css('display', 'none');
    }

});

http://jsfiddle.net/zlajaa1/fbe4p283/1/

Jamiec
  • 133,658
  • 13
  • 134
  • 193
Zlatko Vujicic
  • 353
  • 2
  • 12
  • Here is another article explaining how to stop jQuery animation: http://stackoverflow.com/questions/3701311/jquery-event-when-user-stops-scrolling. Write some code surrounding one of these ideas to create the functionality you are looking for. – puddinman13 Feb 26 '15 at 16:49

1 Answers1

2

You can use the stop() method. The method accepts 2 parameters.

From the Jquery docs:

clearQueue Type: Boolean A Boolean indicating whether to remove queued animation as well. Defaults to false.

jumpToEnd Type: Boolean A Boolean indicating whether to complete the current animation immediately. Defaults to false.

jsfiddle demo

$(window).scroll(function() {
    if ($(window).scrollTop() > 200) {  
        $(".prim").fadeIn(250);
    }
    else {
        $(".prim").stop( true, true ).fadeOut(250);
    }
});

//Sticky bar responsive fix
$(window).resize(function(){
    var width = $(window).width();

    if( width > 1024 && $(window).scrollTop() > 190 ){
        $(".prim").fadeIn(250);
    }
    else{
        $(".prim").css('display', 'none');
    }
    
});
Community
  • 1
  • 1
kasper Taeymans
  • 6,950
  • 5
  • 32
  • 51