你好,我有这个脚本,我想要那个
$(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'});
只是第一次。
答案 0 :(得分:4)
将Margin
的值替换为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;
}
});