如何在滚动循环中对函数进行乘法运算?
我有:
$(window).scroll(function() {
b1Center = $("#block-1").offset().top - ( $(window).height() - divHeight )/2;
b1Bottom = $("#block-1").offset().top - $(window).height()
b1Top = $("#block-1").offset().top + divHeight;
if(getScrollTop() > b1Bottom && getScrollTop() < b1Top){
$("#block-1 .txt").css('marginTop', ( (getScrollTop()) *(1.6)) + 'px');
}...
这需要一直在内部滚动功能redy并且我对所有按钮都有相同的块,所以:
希望这会更有意义。
答案 0 :(得分:1)
试试这个:
$(document).ready(function(){
var divHeight = 700;
$(window).scroll(function() {
$(".blocks").each(function(){
var this = $(this),
Center = $(this).offset().top - ( $(window).height() - divHeight )/2,
Bottom = $(this).offset().top - $(window).height(),
Top = $(this).offset().top + divHeight;
if(getScrollTop() > Bottom && getScrollTop() < Top){
this.find('.txt').css('marginTop', ( (getScrollTop()) *(1.6)) + 'px');
}
});
});
});
答案 1 :(得分:0)
将它放在.scrollTop()循环中:
$('.block').each(function () {
var this_block = $(this);
this_block.whateverFunction(you, want, to, do);
});
确保使用按钮的类而不是id ...