jquery實(shí)現(xiàn)動(dòng)畫菜單的左右滾動(dòng)、漸變及圖形背景滾動(dòng)等效果
本文實(shí)例講述了jquery實(shí)現(xiàn)動(dòng)畫菜單的左右滾動(dòng)、漸變及圖形背景滾動(dòng)等效果。分享給大家供大家參考。具體如下:
這里演示基于jquery實(shí)現(xiàn)的動(dòng)畫菜單,內(nèi)含四種效果的網(wǎng)站菜單,第一種是不帶效果的傳統(tǒng)導(dǎo)航菜單,第二種是帶有圖形滾動(dòng)背景的菜單,第三種是由右向左背景滾動(dòng)的菜單,第四種則是背景色漸變的網(wǎng)站菜單,每一種都很精彩,喜歡Js菜單的可模仿借鑒一下。
運(yù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)畫效果
- jQuery實(shí)現(xiàn)的背景顏色漸變動(dòng)畫效果示例
- jQuery實(shí)現(xiàn)鼠標(biāo)響應(yīng)式淘寶動(dòng)畫效果示例
- jQuery實(shí)現(xiàn)的鼠標(biāo)響應(yīng)緩沖動(dòng)畫效果示例
- jQuery插件Slider Revolution實(shí)現(xiàn)響應(yīng)動(dòng)畫滑動(dòng)圖片切換效果
- 一款基jquery超炫的動(dòng)畫導(dǎo)航菜單可響應(yīng)單擊事件
- jQuery動(dòng)畫animate方法使用介紹
- JQuery動(dòng)畫animate的stop方法使用詳解
- jQuery動(dòng)畫效果animate和scrollTop結(jié)合使用實(shí)例
- 分享8款優(yōu)秀的 jQuery 加載動(dòng)畫和進(jìn)度條插件
- jQuery實(shí)現(xiàn)鼠標(biāo)響應(yīng)式透明度漸變動(dòng)畫效果示例
相關(guān)文章
jquery學(xué)習(xí)筆記 用jquery實(shí)現(xiàn)無(wú)刷新登錄
為了防止以后好久不用生疏,在這里記下,供剛開始學(xué)習(xí)jquery的童鞋們借鑒,我也是剛開始學(xué)jquery,有什么寫的不對(duì)的地方,還請(qǐng)大家指出錯(cuò)誤,共同進(jìn)步。2011-08-08
jquery獲取url參數(shù)及url加參數(shù)的方法
本文給大家介紹jquery獲取url參數(shù)及url參數(shù)的方法,在url中加參數(shù)的方法本文通過(guò)多種方式給大家介紹jquery獲取url參數(shù),感興趣的朋友一起學(xué)習(xí)學(xué)習(xí)吧2015-10-10
jQuery Mobile開發(fā)中日期插件Mobiscroll使用說(shuō)明
這篇文章主要介紹了jQuery Mobile開發(fā)中日期插件Mobiscroll使用說(shuō)明,需要的朋友可以參考下2016-03-03
jQuery EasyUI API 中文文檔 - Dialog對(duì)話框
jQuery EasyUI API 中文文檔 - Dialog對(duì)話框使用說(shuō)明,需要的朋友可以參考下。2011-11-11
jQuery AJAX 方法success()后臺(tái)傳來(lái)的4種數(shù)據(jù)詳解
今天小編就為大家分享一篇jQuery AJAX 方法success()后臺(tái)傳來(lái)的4種數(shù)據(jù)詳解,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-08-08

