Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

$(window).scroll function do only one time

Tags:

jquery

Hello I have this script and I want that

$(window).scroll(function(){

    var FromTop = $(window).scrollTop(); //scroll margin from top
    var RightWrapper = $('.right_wrapper').height(); // Right wrapper height

    var Margin = false;

    var ConentHeight = $('.content_wrapper').height() + RightWrapper; //content height

    if(FromTop > 125 && RightWrapper < 500){
        $('.right_wrapper').addClass('right-fixed-top');
        Margin = true;
    }else{
        $('.right_wrapper').removeClass('right-fixed-top');
    }

    if(Margin){ // <<<<<<PROBLEM IS HERE each scroll 
        $('.content_wrapper').css({height:ConentHeight+'px'});
    }

});

$('.content_wrapper').css({height:ConentHeight+'px'}); only first time.

like image 213
Val Do Avatar asked Aug 26 '26 06:08

Val Do


1 Answers

Replace the value of Margin to false:

$(window).scroll(function(){

    var FromTop = $(window).scrollTop(); //scroll margin from top
    var RightWrapper = $('.right_wrapper').height(); // Right wrapper height

    var Margin = false;

    var ConentHeight = $('.content_wrapper').height() + RightWrapper; //content height

    if(FromTop > 125 && RightWrapper < 500){
        $('.right_wrapper').addClass('right-fixed-top');
        Margin = true;
    }else{
        $('.right_wrapper').removeClass('right-fixed-top');
    }

    if(Margin){
        $('.content_wrapper').css({height:ConentHeight+'px'});
        Margin = false;
    }

});
like image 76
Praveen Kumar Purushothaman Avatar answered Sep 02 '26 09:09

Praveen Kumar Purushothaman