JQuery 缩略图悬停突出显示(隐藏其他缩略图)
我正在尝试复制在 http://www.rockstargames.com/lanoire/ 中找到的效果在第三个框中。当悬停缩略图时,彼此都会变暗。 为了实现这一点,在标准 javascript 中,我将按如下方式处理 onMouseOver 事件:
- 获取对每个缩略图的
- 引用 迭代每个缩略图,但悬停的缩略图并更改不透明度值
我将通过设置超时来处理 onMouseOut 事件,之后每个缩略图拇指将被重置。
我的问题是我对JQuery了解甚少,我不知道我的方法是否正确。我宁愿不去编写代码而最终与框架争论。您有什么建议吗?
I am trying to replicate the effect I found at http://www.rockstargames.com/lanoire/ in the third box. When hovering a thumbnail each other is darkened.
To implement this, in standard javascript I would handle the onMouseOver event as follows:
- Get references to each thumbnail
- Iterate through each thumbnail but the one that was hovered and change the opacity value
And I would handle the onMouseOut event by setting a timeout after which every thumb would be resetted.
My problem is that I have little knowledge of JQuery, and I don't know if my approach is correct. I'd rather not jump into writing code to end up arguing with the framework. Do you have any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您的方法是正确的,但是我认为不需要超时(除非您当然想要超时)
您的逻辑可以转化为这样的内容:
所有图像在页面加载和鼠标移出时都可见。不是悬停图像的图像会变暗。
这是一个工作示例: http://jsfiddle.net/SJ7bp/
Your approach is correct, however I don't see the need for a timeout (unless you wanted one of course)
Your logic translates into something like this:
All images are visible upon page load and mouse out. Images that aren't the hovered images are dimmed out.
Here's a working example: http://jsfiddle.net/SJ7bp/
您可以使用 jquery mouseenter 和 mouseleave 来实现相同的逻辑
step1: http://api .jquery.com/mouseenter/
step2: 使用jquery的this并获取每条记录所需的详细信息,这将获取当前对象的详细信息以及所有属性的详细信息。
然后使用 , jquery .css 属性来设置属性的
step3 http://api.jquery .com/css/
You can use jquery mousenter and mouseleave to implment the same logic
step1: http://api.jquery.com/mouseenter/
step2: Use jquery's this and get the details you want for each record, this gets the details of the current object and you can all the property's.
Then use , jquery .css property's to set the property's
step3 http://api.jquery.com/css/
为每个缩略图指定一个类(例如
.thumbnail
),然后使用 jQuery 设置不透明度
,并应用mouseover
和mouseout
事件:您可以在示例小提琴中看到它的工作原理。
Give each thumbnail a class (for example
.thumbnail
), then use jQuery to set theopacity
, and apply amouseover
andmouseout
event to each:You can see this working in this example fiddle.