如何使用for循环将值赋给jquery对象(How to assign values to a jquery object using for loop)
我已经尝试了几种方法在我的图像上创建视差效果,其中每个图像都有自己的随机速度。 我认为实现它的最佳方法是为每个图像分配一个速度值。 但是我不知道该怎么做。
var img_list = []; $.each($('.gallery_image'), function(e) { img_list.append($(this)); }); for(x in img_list) { ran = Math.round(Math.random() * (11 - 1) + 1); speed = ran.toString() + "px"; x.speed = speed; }这就是我提出的。 我知道x.speed不是一个真实的东西,但我用它来说明我想要完成的事情。
这是一个网站,它正是我在主页面上寻找的内容,但我希望机芯可以滚动。 例
I have tried several ways to create a parallax effect on my images where each image has it's own random speed. I think the best way for me to achieve it is by assigning a speed value to each image. However I am not sure how to do this.
var img_list = []; $.each($('.gallery_image'), function(e) { img_list.append($(this)); }); for(x in img_list) { ran = Math.round(Math.random() * (11 - 1) + 1); speed = ran.toString() + "px"; x.speed = speed; }This is what I came up with. I know that x.speed is not an actual thing, but I am using that to illustrate what I am trying to accomplish.
This is a website that has exactly what I am looking for on the main page, but I want the movement to be on scroll. EXAMPLE
最满意答案
for(var x in img_list) { var ran = Math.round(Math.random() * (11 - 1) + 1); img_list[x].speed = ran.toString() + "px"; } for(var x in img_list) { var ran = Math.round(Math.random() * (11 - 1) + 1); img_list[x].speed = ran.toString() + "px"; }更多推荐
发布评论