gpt4 book ai didi

Jquery 修改每个类实例现有的背景位置?

转载 作者:行者123 更新时间:2023-12-01 05:51:29 24 4
gpt4 key购买 nike

我正在页面上创建视差,该视差正在修改背景位置,只要我希望所有背景从零开始,我所拥有的就可以工作。问题是我不希望它们全部从零开始。有些有预定的起始位置,但我不知道如何从现有位置增加/减少每个类实例的背景位置。您可以在我的代码中看到,我有一行可以检索当前位置,但是每次我尝试使用该数字来修改位置时,我都会得到疯狂的结果,图像到处飞。这是我所拥有的:

jQuery(document).ready(function($){
$(window).scroll(function(){
currentoffset = $(this).scrollTop();
slowOff = Number(currentoffset) / 3;

$( ".full_width_img" ).each(function() {
//bgPosition = $(this).css('backgroundPosition').split(" ");
$(this).css('background-position', '50% -' + slowOff + "px");
});
});
});

如何检索并更新每个实例相对于每个人的现有位置的背景位置属性?

添加了 jfiddle 链接: http://jsfiddle.net/79k8R/

最佳答案

这里有一个逻辑错误。在“each”循环中,您可能需要调整每个图像的背景位置 (Y)。我添加了 (slowOff-240*index) 而不是仅添加“showOff”,这看起来更好。但您始终可以根据自己的需要进行调整,使其变得美观。请看这个 fiddle http://jsfiddle.net/LZhAL/

jQuery(document).ready(function($){
$(window).scroll(function(){
currentoffset = $(this).scrollTop();
slowOff = Number(currentoffset) / 3;

$( ".full_width_img" ).each(function(index) {
//bgPosition = $(this).css('backgroundPosition').split(" ");
$(this).css('background-position', '50% -' + (slowOff-240*index) + "px");
});
});
});

关于Jquery 修改每个类实例现有的背景位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21746385/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com