使用 jQuery 创建背景图像循环
在一个网站上工作,客户希望网站的“背景图像”循环显示 3 张图像。
现在我之前已经创建了循环(或安装了插件)来循环浏览 img 标签...但没有制作一个 jQuery 函数来联系 div 的 css 并为其提供一个新图像以每 7 秒“淡出”一次
...有人知道如何做到这一点吗???
现在我想让图像作为 div 中的 img 标签淡入淡出,但不幸的是,在这种情况下无法做到这一点,因为具有不断变化的背景图像的 div 的大小是可调整的,并且图像比它宽得多,需要定位在它的中心 - 使用 css image-position:center 标签...
感谢您的帮助
working on a website where the client wants the "background image" of the website to cycle through 3 images.
Now I have created cycles before (or installed plugins) to cycle through img tags... but not made a jQuery function that contacts the css of a div and gives it a new image to "fade" to every 7 seconds...
Does anyone have an idea how to do this???
Now I would like to have the images fade through as img tags within a div but unfortunately this cannot be done in this case as the div that has the changing background images is resizable, and has images far wider than it, that need to be positioned in the center of it - hense using the css image-position:center tag...
thanks for the help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我发现您不喜欢通过 div 来执行此操作,但您可以仅对背景颜色进行动画处理。
这是我的问题的解决方案。我使用了两张图片,因此您必须在数组中再添加一个网址,并将
count % 2
更改为count % 3
以适合您的情况(使用三个不同的背景图像)。这是小提琴:http://jsfiddle.net/5uBej/4/
来源:
< strong>JS
CSS
HTML
我希望这些代码行对您有所帮助:-)。
此致。
I saw that you don't prefer to do this by a div but you can animate just the background color.
Here is my solution of the problem. I've used two images so you've got to add one url more into the array and change
count % 2
tocount % 3
to fit into your case (with three different images for background).Here is the fiddle: http://jsfiddle.net/5uBej/4/
And the source:
JS
CSS
HTML
I hope that these lines of code helped you :-).
Best regards.