滚动链接==更改类别。滚出 div == 将类改回来。不工作。帮助
这是我最简单的问题。让我试着把它弄清楚。
我有一个 div
,在本例中称为 "testdiv"
,它附加了一个类名 "menulink"
。 div
内有一个链接。当我将鼠标悬停在链接上时,我希望 div
类更改为 "menulinkHover"
。然而,当我推出 div
时,我希望该类恢复为 “menulink”
。为此,我使用 getElementByID
。滚动链接效果很好,但一旦我滚出 link
,而不是 div
,类就会恢复回来。
这是我到目前为止所拥有的一个小提琴: http://jsfiddle.net/nathanbunn/KJMsf/
我正在使用 jQuery 来解决这个问题,以相同的方式使用 .removeClass
和 .addClass
,但我担心我会遇到同样的问题。我错过了一些东西,我知道我错过了一些东西,但它是什么?要了解我正在寻找的内容,请查看 Harvey Nichols 主页。我知道他们使用 Prototype 作为他们选择的框架。
这可以用我的脚本来完成吗?我是对的吗?我确实错过了一些东西吗?在 jQuery 中可以更好地工作吗?甚至可以用纯 CSS 来完成吗?请帮忙。我完全不知所措。
That's my issue in its simplest terms. Let me try to clear it up.
I have a div
, in this case called "testdiv"
, which has a class name of "menulink"
attached to it. There is a link inside of the div
. When I roll over the link, I want the div
class to change to "menulinkHover"
. When I roll out of the div
, however, I want the class to revert back to "menulink"
. To do this, I am using getElementByID
. Rolling over the link works perfectly, but as soon as I roll out of the link
, not the div
, the class reverts back.
Here is a fiddle with what I have so far: http://jsfiddle.net/nathanbunn/KJMsf/
I'm working on this with jQuery, using .removeClass
and .addClass
in the same manner, but I fear I will get the same issue. I've missed something, I know I've missed something, but what is it? For an idea of what I'm looking for, have a look on the Harvey Nichols homepage. I know they use Prototype for their framework of choice.
Can this be done with the script I have? Am I right and I have indeed missed something? Can it work better in jQuery? Can it be done in pure CSS, even? Please help. I'm at a complete loss.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将 CSS 与 jquery 鼠标事件和淡入/淡出结合起来,你应该得到你想要的。一个例子是:这里
Combine CSS with jquery mouse event and fadein/out, and you should get what you want. An example is : here
我将其设置为使用 JQuery,因为我总是发现它比纯 JavaScript 更好。我通过将链接设置为具有一个 mouseenter 来将类添加到 div,然后 div 本身具有一个 mouseleave 来删除该类来使其工作。现在对我来说效果很好。这是链接:
http://jsfiddle.net/KJMsf/6/
I set it up to use JQuery as I always find it better than pure javascript. I got it to work by setting the link to have a mouseenter that adds a class to the div and then the div itself has a mouseleave that removes the class. It now works fine for me. Here's the link:
http://jsfiddle.net/KJMsf/6/