当鼠标穿过元素时jquery背景图像发生变化
我的老板在网站上看到了这一点:http://event.photoswarm.com/
注意图像如何变化当你浏览专辑时。这样做的缺点是所有缩略图都必须在开始时下载,然后我想这一切都会起作用。
有没有一种方法可以让我在加载图像的同时获得类似的效果?
我猜的问题是:
- 让图像加载得更干净
- 让它们加载得更好,因为某些相册可能有 200 多张照片
- 使用 jquery 插件 - 这个插件似乎是由 photo swarm 制作的,我猜他们不会如果我偷了它,我就太高兴了!
因此,如果有一种方法可以制作某些东西,或者有人知道免费插件,我可以下载,那就太好了。
My boss has seen this on a website: http://event.photoswarm.com/
Notice how the images change as you go across the albums. The downside of this is that all the thumbnail images have to be downloaded at the start and then I guess it all then works.
Is there a way I could get something similar to work while loading the images a little better?
The problem I guess is:
- Make the images load a little cleaner
- Make them load better as some of the albums could have 200+ photos
- Use a jquery plugin - this one seems to have been made by photo swarm and I guess they wouldn't be too chuffed if I stole it!
So if there is a way to make something or anyone knows of a free plugin I can download that would be great.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果您检查元素和资源,您会发现:
http://static.photoswarm.com/js /app_user.js
它使用 jQuery 和 Prototype.js
If you inspect the element and resources you will find this:
http://static.photoswarm.com/js/app_user.js
It uses jQuery and Prototype.js
您可以将所有图像位置存储在一个数组中。然后,只有当您将鼠标悬停在图像上时,它才会加载图像。
You could store all your image locations in an array. Then it only will load the images when you hover over them.
我想您首先通过雅虎工具 SmushIt 获取图像并粉碎它,这会从图像中删除所有不必要的信息。
然后,我将使用您想要在该特定相册上拥有的图像的链接来初始化一个数组,然后只需
在指定相册(例如可以是一个 div)上添加一个
,然后您就可以运行该数组只需使用该数组中的链接更改该 div 的“背景图像”即可。
也许您应该向该操作添加 setTimeout() ,这样就不会运行得那么快。
另一种选择是选择
.hover()
但我不太确定这是否符合您的要求。I suppose you take your images and smush it first of all via the Yahoo Tool SmushIt, this removes all unneceseary information out of your images.
Then I would initialize an array with the links of the images you want to have on that specific album, and then simply add a
on the specified album(which could be a div for example) and by that you run through that array and simply change the "background-image" of that div with your link out of that array.
Maybe you should add a setTimeout() to that action so this does not run through that fast.
An alternate option would be if you choose
.hover()
but I'm not quite sure if this fits your requirements.我认为最好是我回答这个问题,因为我是相关代码的原始作者:)
首先,我们同意您使用代码(尽管这个问题已经存在一年了,所以您可能已经有了) ,我们目前正在进行一次大的重写,并且该代码作为其中的一部分而被贬值。
Fabián 链接到的文件确实包含您需要的代码,但它还包含您不需要的网站其余部分的许多其他代码。您想要的部分实际上非常简单,但发生了一些不同的事情。在该文件的深处,您将看到 PS.CoverLoader 类。
首先,获取页面的所有拇指并开始在后台加载它们。我们假设它们已经被加载。
轻弹非常简单 - 我将只使用伪代码,因为您已经有 js (并且这些天您可能会使用 jquery)。
关于加载大量图像的其他问题。这是一个问题。该系统加载该页面的所有拇指。它的效率很低——有些页面只有 10 或 100 MB。我们尝试为每个包含所有拇指(图像精灵)的相册创建一个长图像,但这实际上不适用于这么多不同的图像。
我的建议是在第一次悬停时加载给定相册的所有图像并将其存储在 js 的数组中。
I think it might be best if I answered this one as I'm the original author of the code in question :)
Firstly, we're ok with you taking the code (though this question is a year old so you probably already have), we're in the middle of a big rewrite at the moment and this code is depreciated as part of that.
The file that Fabián linked to does contain the code that you need, but it also contains a lot of other code for the rest of the site that you don't. The bit that you want is actually quite simple but there are a couple of different things going on. Deep in that file you'll see the PS.CoverLoader class.
Firstly that takes all the thumbs for the page and starts loading them in the background. Let's just assume they've already been loaded.
The flicking is very simple - I'll just use pseudocode as you already have the js there (and you'd probably use jquery these days).
In terms of other questions regarding loading lots of images. It is a problem. This system loads all the thumbs for the page. It's inefficient - some pages are 10s/100s of MB. We tried created a single long image for each album containing all the thumbs (an image sprite) but that doesn't really work with this many different images.
My suggestion would be to load all the images for a given album on first hover and store that in an array in js.