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

在線(xiàn)演示地址如下:
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動(dòng)態(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>
希望本文所述對(duì)大家的jquery程序設(shè)計(jì)有所幫助。
- 基于jquery的direction圖片漸變動(dòng)畫(huà)效果
- jQuery實(shí)現(xiàn)的背景顏色漸變動(dòng)畫(huà)效果示例
- jQuery實(shí)現(xiàn)鼠標(biāo)響應(yīng)式淘寶動(dòng)畫(huà)效果示例
- jQuery實(shí)現(xiàn)的鼠標(biāo)響應(yīng)緩沖動(dòng)畫(huà)效果示例
- jQuery插件Slider Revolution實(shí)現(xiàn)響應(yīng)動(dòng)畫(huà)滑動(dòng)圖片切換效果
- 一款基jquery超炫的動(dòng)畫(huà)導(dǎo)航菜單可響應(yīng)單擊事件
- jQuery動(dòng)畫(huà)animate方法使用介紹
- JQuery動(dòng)畫(huà)animate的stop方法使用詳解
- jQuery動(dòng)畫(huà)效果animate和scrollTop結(jié)合使用實(shí)例
- 分享8款優(yōu)秀的 jQuery 加載動(dòng)畫(huà)和進(jìn)度條插件
- jQuery實(shí)現(xiàn)鼠標(biāo)響應(yīng)式透明度漸變動(dòng)畫(huà)效果示例
相關(guān)文章
jQuery animate(滑塊滑動(dòng)效果代碼)
jQuery animate 滑塊滑動(dòng)效果,學(xué)習(xí)jquery的朋友可以看下。2010-01-01
關(guān)于Jqzoom的使用心得 jquery放大鏡效果插件
Jqzoom是基于jquery的放大鏡效果插件,兼容多款瀏覽器,喜歡的朋友可以測(cè)試下。2010-04-04
jquery+css3實(shí)現(xiàn)的經(jīng)典彈出層效果示例
這篇文章主要介紹了jquery+css3實(shí)現(xiàn)的經(jīng)典彈出層效果,結(jié)合實(shí)例形式分析了jquery+css3實(shí)現(xiàn)彈出層具體原理、步驟與相關(guān)操作技巧,需要的朋友可以參考下2020-05-05
jQuery函數(shù)map()和each()介紹及異同點(diǎn)分析
這篇文章主要介紹了jQuery函數(shù)map()和each()介紹及異同點(diǎn)分析,需要的朋友可以參考下2014-11-11
分享20個(gè)提升網(wǎng)站界面體驗(yàn)的jQuery插件
今天為大家整理20個(gè)提升網(wǎng)站界面的體驗(yàn)的jQuery插件,這些都是比較“新款”的代碼,喜歡的請(qǐng)用到你的網(wǎng)站項(xiàng)目上吧2014-12-12
JQuery1.4+ Ajax IE8 內(nèi)存泄漏問(wèn)題
將JQuery1.2.6升級(jí)到JQuery1.4,有幾天下班沒(méi)有關(guān)閉ajax輪詢(xún)網(wǎng)頁(yè),第二天早上來(lái),內(nèi)存耗盡,發(fā)現(xiàn)此內(nèi)存泄漏在IE6上不存在(IE7未測(cè)試),IE8上存在2010-10-10

