如何使用for循环将值赋给jquery对象(How to assign values to a jquery object using for loop)

编程入门 行业动态 更新时间:2024-10-08 04:28:39
如何使用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"; }

更多推荐

本文发布于:2023-08-07 11:32:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1464048.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何使用   对象   jquery   将值赋   loop

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!