请帮我处理以下代码。我可以使用图像来创建圆形菜单并让它变得简单,但我想使用CSS和Jquery使页面超级快速,并从这个项目中学到一些东西。我想要做的是更改(动画)悬停菜单项周围的圆形形状的颜色。我认为代码非常自我解释,但如果有什么不清楚,请告诉我。
<html>
<head>
<script type="text/javascript" src="jquery.js"></script>
<script src="jquery.color.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
var itemnumber = '';
$('#menu li').hover(function () {
itemnumber = '#item' + $(this).text();
$(itemnumber).animate({color: "#abcdef"}, 1000);
}).mouseleave(function () {
$(itemnumber).animate({color: "#B1AC8F"}, 1000);
});
});
</script>
<style type="text/css">
body {
width: 810px;
height: 800px;
background-image: linear-gradient(bottom, rgb(255,255,255) 0%, rgb(206,203,183) 34%, rgb(177,172,143) 82%);
background-image: -o-linear-gradient(bottom, rgb(255,255,255) 0%, rgb(206,203,183) 34%, rgb(177,172,143) 82%);
background-image: -moz-linear-gradient(bottom, rgb(255,255,255) 0%, rgb(206,203,183) 34%, rgb(177,172,143) 82%);
background-image: -webkit-linear-gradient(bottom, rgb(255,255,255) 0%, rgb(206,203,183) 34%, rgb(177,172,143) 82%);
background-image: -ms-linear-gradient(bottom, rgb(255,255,255) 0%, rgb(206,203,183) 34%, rgb(177,172,143) 82%);
background-image: -webkit-gradient(linear,left bottom,left top,color-stop(0, rgb(255,255,255)),color-stop(0.34, rgb(206,203,183)),color-stop(0.82, rgb(177,172,143)));
}
#menu ul { list-style:none; }
#logo { width:250px; margin:0 285px; }
.circle { width: 150px; height: 150px; background: transparent; -moz-border-radius: 100px; -webkit-border-radius: 100px; border-radius: 100px; border:10px; border-style:solid; color:#B8A36E; }
.oval { margin: 0.5px 10px; width: 130px; height: 50px; background: #B8A36E; -moz-border-radius: 100px / 50px; -webkit-border-radius: 100px / 50px; border-radius: 100px / 50px; }
#itempic {position:relative; margin: -1px -12px; z-index:-1;}
#item1 {position:absolute; left: 160px; top:170px; }
#item2 {position:absolute; left: 335px; top:170px; }
#item3 {position:absolute; left: 510px; top:170px; }
#item4 {position:absolute; left: 245px; top:325px; }
#item5 {position:absolute; left: 420px; top:325px; }
#item6 {position:absolute; left: 160px; top:480px; }
#item7 {position:absolute; left: 335px; top:480px; }
#item8 {position:absolute; left: 510px; top:480px; }
#item9 {position:absolute; left: 245px; top:635px; }
#item10 {position:absolute; left: 420px; top:635px; }
</style>
</head>
<body>
<img id="logo" src="logo.png">
<div id="menu">
<ul>
<li><div class="circle" id="item1"><div class="oval"><img id="itempic" src="Item1.png"></div></div></li>
<li><div class="circle" id="item2"><div class="oval"><img id="itempic" src="Item2.png"></div></div></li>
<li><div class="circle" id="item3"><div class="oval"><img id="itempic" src="Item3.png"></div></div></li>
<li><div class="circle" id="item4"><div class="oval"><img id="itempic" src="Item4.png"></div></div></li>
<li><div class="circle" id="item5"><div class="oval"><img id="itempic" src="Item5.png"></div></div></li>
<li><div class="circle" id="item6"><div class="oval"><img id="itempic" src="Item1.png"></div></div></li>
<li><div class="circle" id="item7"><div class="oval"><img id="itempic" src="Item2.png"></div></div></li>
<li><div class="circle" id="item8"><div class="oval"><img id="itempic" src="Item3.png"></div></div></li>
<li><div class="circle" id="item9"><div class="oval"><img id="itempic" src="Item4.png"></div></div></li>
<li><div class="circle" id="item10"><div class="oval"><img id="itempic" src="Item5.png"></div></div></li>
</ul>
</div>
</body>
</html>
我发现了这个问题..感谢帮助人员!
<html>
<head>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="jquery.color.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
var itemnumber = '';
var itemoval = '';
$('#menu li').hover(function () {
itemnumber = '#item' + ($('#menu li').index(this) + 1);
itemoval = itemnumber + '-oval';
$(itemnumber).animate({color: "#F97780"}, 500);
$(itemoval).animate({backgroundColor: "#F97780"}, 500);
}).mouseleave(function () {
$(itemnumber).animate({color: "#B8A36E"}, 500);
$(itemoval).animate({backgroundColor: "#B8A36E"}, 500);
});
});
</script>
<style type="text/css">
body {
width: 810px;
height: 800px;
background-image: linear-gradient(bottom, rgb(255,255,255) 0%, rgb(206,203,183) 34%, rgb(177,172,143) 82%);
background-image: -o-linear-gradient(bottom, rgb(255,255,255) 0%, rgb(206,203,183) 34%, rgb(177,172,143) 82%);
background-image: -moz-linear-gradient(bottom, rgb(255,255,255) 0%, rgb(206,203,183) 34%, rgb(177,172,143) 82%);
background-image: -webkit-linear-gradient(bottom, rgb(255,255,255) 0%, rgb(206,203,183) 34%, rgb(177,172,143) 82%);
background-image: -ms-linear-gradient(bottom, rgb(255,255,255) 0%, rgb(206,203,183) 34%, rgb(177,172,143) 82%);
background-image: -webkit-gradient(linear,left bottom,left top,color-stop(0, rgb(255,255,255)),color-stop(0.34, rgb(206,203,183)),color-stop(0.82, rgb(177,172,143)));
}
#menu ul { list-style:none; }
#logo { width:250px; margin:0 285px; }
.circle { width: 150px; height: 150px; background: transparent; -moz-border-radius: 100px; -webkit-border-radius: 100px; border-radius: 100px; border:10px; border-style:solid; color:#B8A36E; }
.oval { z-index:-1; margin: 0.5px 10px; width: 130px; height: 50px; background: #B8A36E; -moz-border-radius: 100px / 50px; -webkit-border-radius: 100px / 50px; border-radius: 100px / 50px; }
#itempic {position:relative; margin: -1px -12px; z-index:-1;}
#item1 {position:absolute; left: 160px; top:170px; }
#item2 {position:absolute; left: 335px; top:170px; }
#item3 {position:absolute; left: 510px; top:170px; }
#item4 {position:absolute; left: 245px; top:325px; }
#item5 {position:absolute; left: 420px; top:325px; }
#item6 {position:absolute; left: 160px; top:480px; }
#item7 {position:absolute; left: 335px; top:480px; }
#item8 {position:absolute; left: 510px; top:480px; }
#item9 {position:absolute; left: 245px; top:635px; }
#item10 {position:absolute; left: 420px; top:635px; }
</style>
</head>
<body>
<img id="logo" src="logo.png">
<div id="menu">
<ul>
<li><div class="circle" id="item1"><div class="oval" id="item1-oval"><img id="itempic" src="Item1.png"></div></div></li>
<li><div class="circle" id="item2"><div class="oval" id="item2-oval"><img id="itempic" src="Item2.png"></div></div></li>
<li><div class="circle" id="item3"><div class="oval" id="item3-oval"><img id="itempic" src="Item3.png"></div></div></li>
<li><div class="circle" id="item4"><div class="oval" id="item4-oval"><img id="itempic" src="Item4.png"></div></div></li>
<li><div class="circle" id="item5"><div class="oval" id="item5-oval"><img id="itempic" src="Item5.png"></div></div></li>
<li><div class="circle" id="item6"><div class="oval" id="item6-oval"><img id="itempic" src="Item1.png"></div></div></li>
<li><div class="circle" id="item7"><div class="oval" id="item7-oval"><img id="itempic" src="Item2.png"></div></div></li>
<li><div class="circle" id="item8"><div class="oval" id="item8-oval"><img id="itempic" src="Item3.png"></div></div></li>
<li><div class="circle" id="item9"><div class="oval" id="item9-oval"><img id="itempic" src="Item4.png"></div></div></li>
<li><div class="circle" id="item10"><div class="oval" id="item10-oval"><img id="itempic" src="Item5.png"></div></div></li>
</ul>
</div>
</body>
</html>
答案 0 :(得分:2)
您需要查看jQuery UI Color动画here。
您可以通过添加此脚本标记来使用google CDN添加jQuery UI。
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery-ui/1.8.21/jquery-ui.min.js"></script>
基本上它归结为链接jQuery UI,然后将你的悬停功能更改为mouseenter
函数。
查看此working example。
答案 1 :(得分:1)
看看:http://jsfiddle.net/ufomammut66/ZsX8e/
我将您的悬停事件更改为mouseenter事件。如果你把它改回来悬停在jsfiddle中,你会注意到'in'logging语句会在出路时触发两次(查找我留下的console.log语句),这是我们不想要的。
我还将jquery选择器更改为您的circle类。我这样做是因为看起来好像你看不到li元素(可能只是缺少图像)你想要它在进入圆形元素时触发。
我不清楚您尝试使用itemnumber,但似乎您正在尝试重建圆元素ID以选择它。我们不需要这样做,因为this
元素将引用我们正在进入或离开的当前元素。
注意:我假设您使用此http://www.bitstorm.org/jquery/color-animation/作为jquery.color.min.js
导入。 jsFiddle导入了这个。
希望这有帮助。