如何将 jQuery 悬停脚本应用到悬停链接中的 div 类?
我认为我的问题不太清楚,但希望我能在这里说得更清楚。
我有以下悬停脚本:
$("nav a#index").hover(
function() {
$(".current").animate({
opacity: 1
}, {
duration: 300,
specialEasing: {
opacity: 'linear',
},
});
}, function() {
$(".current").animate({
opacity: 0
}, {
duration: 3000,
specialEasing: {
opacity: 'linear',
},
});
});
我用它来淡入具有绝对定位的 div 中的图像:
<div id="nav1">
<a href="index.html" class="fade nav top current" id="index">
<div class="nav-image"><img src="images/bodhi-leaf-green.png"></div>
<div id="current"><img src="images/bodhi-leaf-green.png"></div>
<div class="text"><img src="images/home.png"></div>
</a>
</div>
因为我需要在多个导航 div 上实现悬停效果,例如 nav2、nav3 等,所以我需要每个导航的悬停脚本,或者更确切地说,我希望找到一种编写适用于我所有导航链接的脚本的方法,因此这将以:开始
$("nav a").hover(
,然后会有类似的内容:
function() {
$(this ".current").animate({......
即我正在寻找一种引用 div 类的方法在特定的 href 链接中,以便我可以淡入这个。我希望这更清楚!
感谢您的任何帮助。
缺口
I don't think my question is as clear as it could be, but hopefully I can make it clearer here.
I have the following hover script:
$("nav a#index").hover(
function() {
$(".current").animate({
opacity: 1
}, {
duration: 300,
specialEasing: {
opacity: 'linear',
},
});
}, function() {
$(".current").animate({
opacity: 0
}, {
duration: 3000,
specialEasing: {
opacity: 'linear',
},
});
});
I use it to fade in images in a div with absolute positioning:
<div id="nav1">
<a href="index.html" class="fade nav top current" id="index">
<div class="nav-image"><img src="images/bodhi-leaf-green.png"></div>
<div id="current"><img src="images/bodhi-leaf-green.png"></div>
<div class="text"><img src="images/home.png"></div>
</a>
</div>
Because I am needing the hover effect on multiple nav divs, e.g. nav2, nav3, etc., I need hover scripts for each of these, or rather, I am hoping to find a way of writing one script that would work for all of my nav links, so this would start with:
$("nav a").hover(
and then would have something like:
function() {
$(this ".current").animate({......
i.e. I am looking for a way of referring to a div class in a particular a href link so that I can fade this in. I hope this is clearer!
Thanks for any help.
Nick
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将
$(".current")
更改为$(".current", this)
:修改后,仅包含.current
元素链接将被更改。修改选择器:
div[id^=nav]
将选择所有ID以“nav
”开头的DIV元素注意:更改
id="index"
到class="index"
。Change
$(".current")
to$(".current", this)
: After this modification, only the.current
element within the link will be changed.Modify the selector:
div[id^=nav]
will select all DIV elements whose ID start with "nav
"Note: Change
id="index"
toclass="index"
.试试这个:
Try this one: