gpt4 book ai didi

NavBar 的 jQuery 悬停效果不起作用?

转载 作者:太空狗 更新时间:2023-10-29 16:01:47 25 4
gpt4 key购买 nike

出于某种原因,我无法让悬停效果发挥作用
HTML:

<div id="navbarcontainer">
<ul>
<li id="left" class="current">
<a id="current">Home</a></li>
<li class="dependant1">
<a id="dependant1">Services</a></li>
<li id="right" class="dependant2">
<a id="dependant2">Contact</a></li>
</ul>
</div>

CSS:

#navbarcontainer {
margin: 0;
padding: 0;
height: 50px;
background: #01216D;
}

#navbarcontainer ul {
clear: both;
margin: 0;
padding: 0;
list-style: none;
}

#navbarcontainer li {
display: inline-block;
height: 50px;
width: 100px;
list-style: none;
text-align: center;
-moz-transition: .5s;
-o-transition: .5s;
-webkit-transition: .5s;
transition: .5s;
/* Firefox 4 */
/* Opera */
/* Safari and Chrome */
}

#navbarcontainer ul li a {
text-decoration: none;
line-height: 50px;
width: 100px;
font-size: 20px;
font-family: Calibri;
cursor: pointer;
}

#left {
margin-right: 40px;
margin-left: 20px;
}

#right {
margin-left: 40px;
}

.current {
background: #fff;
}

#current {
color: #01216D;
font-weight: bold;
}

#dependant1, #dependant2 {
color: #fff;
}

jQuery:

$("#dependant1").hover(function () {
$('.dependant1').stop().animate({background: '#fff' }, "slow");
$('#dependant1').stop().animate({color: '#01216D', 'font-weight': 'bold'}, "slow");
}, function () {
$('.dependant1').stop().animate({ background: 'none' }, "slow");
$('#dependant1').stop().animate({color: '#fff', 'font-weight': 'normal'}, "slow");
});

我觉得它与 jQuery 有关,但我在 document.load 中有它,所以我不明白为什么它不起作用。

最佳答案

您需要在 jQuery 之后包含 jQuery UI Library :

LIVE DEMO

$("#navbarcontainer li").hover(function () {
$(this).find('a').stop().animate({ color: '#01216D', backgroundColor: '#fff'}, 800);
}, function () {
$(this).find('a').stop().animate({ color: '#fff', backgroundColor: '#01216D'}, 800);
});

HTML:

 <div id="navbarcontainer">
<ul>
<li><a id="current">Home</a></li>
<li><a>Services</a></li>
<li><a>Contact</a></li>
</ul>
</div>

CSS:

#navbarcontainer {
margin: 0;
padding: 0;
background: #01216D;
}
#navbarcontainer ul {
clear: both;
margin: 0;
padding: 0;
list-style: none;
overflow:hidden;
}
#navbarcontainer li {
list-style: none;
text-align: center;
-moz-transition: .5s;
-o-transition: .5s;
-webkit-transition: .5s;
transition: .5s;
}
#navbarcontainer ul li a {
float:left;
color:#fff;
background: #01216D;
padding:10px 30px;
text-decoration: none;
line-height: 50px;
font-size: 20px;
font-family: Calibri;
cursor: pointer;
}
#current {
background: #fff !important;
color: #01216D !important;
font-weight: bold;
}

或者另一个脚本:

$("#navbarcontainer li").on('mouseenter mouseleave',function ( e ) {
var set = e.type=='mouseenter' ? {c:"#01216D", bg:"#fff"} : {c:"#fff", bg:"#01216D"} ;
$('a', this).stop().animate({ color: set.c, backgroundColor: set.bg}, 800);
});

关于NavBar 的 jQuery 悬停效果不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15838112/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com