jquery實現(xiàn)動畫菜單的左右滾動、漸變及圖形背景滾動等效果
本文實例講述了jquery實現(xiàn)動畫菜單的左右滾動、漸變及圖形背景滾動等效果。分享給大家供大家參考。具體如下:
這里演示基于jquery實現(xiàn)的動畫菜單,內(nèi)含四種效果的網(wǎng)站菜單,第一種是不帶效果的傳統(tǒng)導(dǎo)航菜單,第二種是帶有圖形滾動背景的菜單,第三種是由右向左背景滾動的菜單,第四種則是背景色漸變的網(wǎng)站菜單,每一種都很精彩,喜歡Js菜單的可模仿借鑒一下。
運行效果截圖如下:

在線演示地址如下:
http://demo.jb51.net/js/2015/jquery-flash-style-cha-menu-codes/
具體代碼如下:
<!DOCTYPE html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk" />
<title>jQuery動態(tài)背景導(dǎo)航菜單</title>
<style type="text/css">
h2{clear: both;padding-top: 20px;}
ul{list-style: none;margin: 0;padding: 0;}
li{float: left;width: 100px;margin: 0;padding: 0;text-align: center;}
li a{display: block;padding: 5px 10px;height: 100%;color: #FFF;text-decoration: none;border-right: 1px solid #FFF;}
li a{background: url(images/bg2.jpg) repeat 0 0;}
li a: hover, li a: focus, li a: active{background-position: -150px 0;}
#a a{background: url(images/bg.jpg) repeat -20px 35px;}
#b a{background: url(images/bg2.jpg) repeat 0 0;}
#c a{background: url(images/bg3.jpg) repeat 0 0;}
#d a{background: url(images/bg4.jpg) repeat 0 0;}
</style>
<script type="text/javascript" src="jquery-1.6.2.min.js"></script>
<script type="text/javascript">
(function($) {
$.extend($.fx.step,{
backgroundPosition: function(fx) {
if (fx.state === 0 && typeof fx.end == 'string') {
var start = $.curCSS(fx.elem,'backgroundPosition');
start = toArray(start);
fx.start = [start[0],start[2]];
var end = toArray(fx.end);
fx.end = [end[0],end[2]];
fx.unit = [end[1],end[3]];
}
var nowPosX = [];
nowPosX[0] = ((fx.end[0] - fx.start[0]) * fx.pos) + fx.start[0] + fx.unit[0];
nowPosX[1] = ((fx.end[1] - fx.start[1]) * fx.pos) + fx.start[1] + fx.unit[1];
fx.elem.style.backgroundPosition = nowPosX[0]+' '+nowPosX[1];
function toArray(strg){
strg = strg.replace(/left|top/g,'0px');
strg = strg.replace(/right|bottom/g,'100%');
strg = strg.replace(/([0-9\.]+)(\s|\)|$)/g,"$1px$2");
var res = strg.match(/(-?[0-9\.]+)(px|\%|em|pt)\s(-?[0-9\.]+)(px|\%|em|pt)/);
return [parseFloat(res[1],10),res[2],parseFloat(res[3],10),res[4]];
}
}
});
})(jQuery);
</script>
<script type="text/javascript">
$(function(){
$('#a a')
.css( {backgroundPosition: "-20px 35px"} )
.mouseover(function(){
$(this).stop().animate({backgroundPosition:"(-20px 94px)"}, {duration:500})
})
.mouseout(function(){
$(this).stop().animate({backgroundPosition:"(40px 35px)"}, {duration:200, complete:function(){
$(this).css({backgroundPosition: "-20px 35px"})
}})
})
$('#b a')
.css( {backgroundPosition: "0 0"} )
.mouseover(function(){
$(this).stop().animate({backgroundPosition:"(-150px 0)"}, {duration:500})
})
.mouseout(function(){
$(this).stop().animate({backgroundPosition:"(-300px 0)"}, {duration:200, complete:function(){
$(this).css({backgroundPosition: "0 0"})
}})
})
$('#c a')
.css( {backgroundPosition: "0 0"} )
.mouseover(function(){
$(this).stop().animate({backgroundPosition:"(0 -250px)"}, {duration:500})
})
.mouseout(function(){
$(this).stop().animate({backgroundPosition:"(0 0)"}, {duration:500})
})
$('#d a')
.css( {backgroundPosition: "0 0"} )
.mouseover(function(){
$(this).stop().animate({backgroundPosition:"(0 -250px)"}, {duration:500})
})
.mouseout(function(){
$(this).stop().animate({backgroundPosition:"(0 0)"}, {duration:500})
})
});
</script>
<meta http-equiv="Content-Type" content="text/html;charset=gbk">
</head>
<body>
<h1>jQuery Background Position</h1>
<h2>Example 0: No Script</h2>
<ul id="noscript">
<li><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Contact</a></li>
</ul>
<h2>Example A: Top down</h2>
<ul id="a">
<li><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Contact</a></li>
</ul>
<h2>Example B: Right left</h2>
<ul id="b">
<li><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Contact</a></li>
</ul>
<h2>Example C: Fade 1-colour</h2>
<ul id="c">
<li><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Contact</a></li>
</ul>
<h2>Example D: Fade 2-colour</h2>
<ul id="d">
<li><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Contact</a></li>
</ul>
</body>
</html>
希望本文所述對大家的jquery程序設(shè)計有所幫助。
- 基于jquery的direction圖片漸變動畫效果
- jQuery實現(xiàn)的背景顏色漸變動畫效果示例
- jQuery實現(xiàn)鼠標(biāo)響應(yīng)式淘寶動畫效果示例
- jQuery實現(xiàn)的鼠標(biāo)響應(yīng)緩沖動畫效果示例
- jQuery插件Slider Revolution實現(xiàn)響應(yīng)動畫滑動圖片切換效果
- 一款基jquery超炫的動畫導(dǎo)航菜單可響應(yīng)單擊事件
- jQuery動畫animate方法使用介紹
- JQuery動畫animate的stop方法使用詳解
- jQuery動畫效果animate和scrollTop結(jié)合使用實例
- 分享8款優(yōu)秀的 jQuery 加載動畫和進(jìn)度條插件
- jQuery實現(xiàn)鼠標(biāo)響應(yīng)式透明度漸變動畫效果示例
相關(guān)文章
關(guān)于Jqzoom的使用心得 jquery放大鏡效果插件
Jqzoom是基于jquery的放大鏡效果插件,兼容多款瀏覽器,喜歡的朋友可以測試下。2010-04-04
jquery+css3實現(xiàn)的經(jīng)典彈出層效果示例
這篇文章主要介紹了jquery+css3實現(xiàn)的經(jīng)典彈出層效果,結(jié)合實例形式分析了jquery+css3實現(xiàn)彈出層具體原理、步驟與相關(guān)操作技巧,需要的朋友可以參考下2020-05-05
jQuery函數(shù)map()和each()介紹及異同點分析
這篇文章主要介紹了jQuery函數(shù)map()和each()介紹及異同點分析,需要的朋友可以參考下2014-11-11
JQuery1.4+ Ajax IE8 內(nèi)存泄漏問題
將JQuery1.2.6升級到JQuery1.4,有幾天下班沒有關(guān)閉ajax輪詢網(wǎng)頁,第二天早上來,內(nèi)存耗盡,發(fā)現(xiàn)此內(nèi)存泄漏在IE6上不存在(IE7未測試),IE8上存在2010-10-10

