简体   繁体   English

将鼠标悬停在一个元素上影响另一个

[英]Hover over one element affect another?

Take a look: a link . 看一看: 一个链接 You can see that the icons at the top menu bar turn blue when you hover over it and also, the page links below it turn white when you hover over them... I would like for both of them to do their hover effect when you mouseover one or the other... In essence, I would like the icons to turn blue when you hover over the page links and I would like the page links to turn white when you hover over the icons (obviously I want the only the icon above the page link to light up when it's appropriate page link is being hovered and vice a versa). 您可以看到顶部菜单栏上的图标在您将鼠标悬停在其上时变为蓝色,并且当您将鼠标悬停在它们上方时,它下面的页面链接会变为白色...我希望他们两个都可以在您进行悬停效果时鼠标悬停其中一个......本质上,我希望当你将鼠标悬停在页面链接上时,图标会变成蓝色,我希望当你将鼠标悬停在图标上时,页面链接会变为白色(显然我只想要图标在页面链接上方,当正确的页面链接被悬停时点亮,反之亦然)。

I am using jquery for the image hover effect... 我正在使用jquery进行图像悬停效果...

and the page link code is just a simple css hover a code. 页面链接代码只是一个简单的css悬停代码。 I would like for these two to be linked together as one unit somehow. 我希望将这两者作为一个单元联系在一起。

I was also wondering if the icon could stay lit up after clicking it (TO show which page you are on)... 我也想知道点击它后图标是否可以保持亮起(显示你所在的页面)...

ALSO... 也...

I have a problem where when the website is minimized into a smaller window... when you horizontally scroll... the wrapper gets cut off and all you see is white space! 我有一个问题,当网站最小化到一个较小的窗口...当你水平滚动...包装被切断,所有你看到的是白色空间! I've played around with it alot and it was no use! 我玩过它很多,没用! I did a float left, but then I couldn't center it! 我做了一个浮动,但后来我无法居中!

If anybody could help out with these two problems, it would be greatly appreciated! 如果有人可以帮助解决这两个问题,我们将不胜感激!

Using javascript to swap images is pretty old-hat. 使用javascript交换图像非常古老。 You should probably consolidate the img and a into a single element and use a css hover selector to swap the background-image ( like so ). 您应该将imga合并到一个元素中,并使用css悬停选择器来交换背景图像( 如此 )。

[Edit] : Here's an example using css-sprites. [编辑]这是一个使用css-sprites的例子。 If you're going to use sprites, you should probably combine all of those nav images into one image to conserve http requests. 如果您要使用精灵,您可能应该将所有这些导航图像合并到一个图像中以保存http请求。

This isn't too difficult to achieve. 这并不难实现。 Instead of using a:hover , use li:hover a , which will work when you hover over any part of the <li> , whether it's the link or the image. 而不是使用a:hover ,使用li:hover a ,当您将鼠标悬停在<li>任何部分上时,无论是链接还是图像,都可以使用。

Preview: http://jsfiddle.net/Wexcode/FZjzG/ 预览: http//jsfiddle.net/Wexcode/FZjzG/

As you can see, I actually removed your image tag and placed it as a background image inside of your <a> tag. 如您所见,我实际上删除了您的图像标记,并将其作为背景图像放在<a>标记内。 This technique is much better than using images and jQuery. 这种技术比使用图像和jQuery要好得多。

If you like using this technique, there are better ways of doing it. 如果你喜欢使用这种技术,有更好的方法。 Read up on CSS Sprites if you're interested in learning more. 如果您有兴趣了解更多信息,请阅读CSS Sprites


Edit: 编辑:
To add your current state, you have two ways of going about it. 要添加当前状态,您有两种方法可以实现。 An easy way would just be to add the class current to the navigation item that is the "current" page. 一种简单的方法就是将类current添加到作为“当前”页面的导航项。

See: http://jsfiddle.net/Wexcode/FZjzG/1/ 请参阅: http//jsfiddle.net/Wexcode/FZjzG/1/


Please post your other problem in another question... you should try to keep one question to each post. 请在另一个问题中发布您的其他问题...您应该尝试在每个帖子中保留一个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM