$(window).scroll(function () { var wtop = $(window).scrolltop(); //滚动条的垂直偏移 var wh = $(window).height(); //可视区域的高度 $('.sjctop').each(function() { var divtop = $(this).offset().top-(wh/2); //div当前的偏移-可视区域的高度 var divtopw = (divtop-wtop)/10+20; //div当前的偏移-可视区域的高度-滚动条的垂直偏移 动态数值 动态幅度 $(this).css("transform","translate(0px,"+ divtopw +"px)"); //当前div的偏移值 }); $('.sjcright').each(function() { var divtop = $(this).offset().top-(wh/2); var divtopw = (divtop-wtop)/10+30; $(this).css("transform","translate(" + -divtopw +"px,0px)"); }); $('.sjcleft').each(function() { var divtop = $(this).offset().top-(wh/2); var divtopw = (divtop-wtop)/10+30; $(this).css("transform","translate("+ divtopw +"px,0px)"); }); $('.sjcbottom').each(function() { var divtop = $(this).offset().top-(wh/2); var divtopw = (divtop-wtop)/10-20; $(this).css("transform","translate(0px,"+ -divtopw +"px)"); }); $('.leftwow').each(function() { var litop = $(this).offset().top-wh/3*2; //滑动至距离底部1/3 var sstop = litop - wtop; if (litop >= wtop) { //滑动至距离底部1/3 停止改变 $(this).css({'transform':"translate("+ -(sstop)/5 +"px,0px)",'opacity': 1-sstop/600}); //动态改变位移 透明度 } else{ $(this).css({'transform':"translate(0,0",'opacity':"1"}); } }); $('.rightwow').each(function() { var litop = $(this).offset().top-wh/3*2; var sstop = litop - wtop; if (litop >= wtop) { $(this).css({'transform':"translate("+ (sstop)/5 +"px,0px)",'opacity': 1-sstop/600}); } else{ $(this).css({'transform':"translate(0,0",'opacity':"1"}); } }); $('.bottomwow').each(function() { var litop = $(this).offset().top-wh/3*2; var sstop = litop - wtop; if (litop >= wtop) { $(this).css({'transform':"translate(0px,"+ (sstop)/5 +"px)",'opacity': 1-sstop/600}); } else{ $(this).css({'transform':"translate(0,0",'opacity':"1"}); } }); });