jQuery實(shí)現(xiàn)的類flash菜單效果代碼
更新時(shí)間:2010年05月17日 22:16:27 作者:
這里要說的就是一個(gè)菜單的hover的效果,一般我們通過CSS的偽類:hover實(shí)現(xiàn)的菜單切換都比較單調(diào),因?yàn)閮H僅是一個(gè)簡單的圖片的變化,不像很多flash菜單一樣變化非常的平滑,但是這里我們就是要用非flash的技術(shù)實(shí)現(xiàn)一個(gè)平滑的hover效果。
先來看看效果:http://demo.jb51.net/js/jquery_flash/demo.htm
因?yàn)橄旅娴膍enu和上面的logo的實(shí)現(xiàn)原理一樣,為了簡化起見,我們這里只拿logo部分的代碼來說明一下原理:
HTML代碼:
<a id="logotype" href=""><span>Logo Type</span></a>
CSS代碼:
a#logotype{ background: url(logotype.jpg) no-repeat top left; display: block; position: relative; height: 70px; width: 119px; } a#logotype span{display:none} a#logotype .hover { background: url(logotype.jpg) no-repeat bottom left; display: block; position: absolute; top: 0; left: 0; height: 70px; width: 119px; } a#logotype{
background: url(logotype.jpg) no-repeat top left;
display: block;
position: relative;
height: 70px;
width: 119px;
}
a#logotype span{display:none}
a#logotype .hover {
background: url(logotype.jpg) no-repeat bottom left;
display: block;
position: absolute;
top: 0;
left: 0;
height: 70px;
width: 119px;
}
這里有一個(gè).hover的class,從html中并沒有發(fā)現(xiàn),不要著急,這個(gè)在后面的js中會用到。
JS代碼:
$(function() { var fadeSpeed = ($.browser.safari ? 600 : 450); $('#logotype').append('<span class="hover"></span>'); $('.hover').css('opacity', 0); $('.hover').parent().hover(function() { $('.hover', this).stop().animate({ 'opacity': 1 }, fadeSpeed) }, function() { $('.hover', this).stop().animate({ 'opacity': 0 }, fadeSpeed) }); }); $(function() {
var fadeSpeed = ($.browser.safari ? 600 : 450);
$('#logotype').append('<span class="hover"></span>');
$('.hover').css('opacity', 0);
$('.hover').parent().hover(function() {
$('.hover', this).stop().animate({
'opacity': 1
},
fadeSpeed)
},
function() {
$('.hover', this).stop().animate({
'opacity': 0
},
fadeSpeed)
});
});
這段JS很清楚的描述了該效果的實(shí)現(xiàn)原理:首先在鏈接中創(chuàng)建一個(gè)class為hover的span(這個(gè)span是鼠標(biāo)放到連接上時(shí)的現(xiàn)實(shí)效果),并且將其透明度設(shè)置為0,然后當(dāng)鼠標(biāo)移到連接上時(shí),將該span的透明逐漸調(diào)整為1,這樣上面的span就會覆蓋a的默認(rèn)效果,這樣就實(shí)現(xiàn)我們的動畫效果。
基于jQuery實(shí)現(xiàn)的仿flash菜單效果
因?yàn)橄旅娴膍enu和上面的logo的實(shí)現(xiàn)原理一樣,為了簡化起見,我們這里只拿logo部分的代碼來說明一下原理:
HTML代碼:
復(fù)制代碼 代碼如下:
<a id="logotype" href=""><span>Logo Type</span></a>
CSS代碼:
復(fù)制代碼 代碼如下:
a#logotype{ background: url(logotype.jpg) no-repeat top left; display: block; position: relative; height: 70px; width: 119px; } a#logotype span{display:none} a#logotype .hover { background: url(logotype.jpg) no-repeat bottom left; display: block; position: absolute; top: 0; left: 0; height: 70px; width: 119px; } a#logotype{
background: url(logotype.jpg) no-repeat top left;
display: block;
position: relative;
height: 70px;
width: 119px;
}
a#logotype span{display:none}
a#logotype .hover {
background: url(logotype.jpg) no-repeat bottom left;
display: block;
position: absolute;
top: 0;
left: 0;
height: 70px;
width: 119px;
}
這里有一個(gè).hover的class,從html中并沒有發(fā)現(xiàn),不要著急,這個(gè)在后面的js中會用到。
JS代碼:
復(fù)制代碼 代碼如下:
$(function() { var fadeSpeed = ($.browser.safari ? 600 : 450); $('#logotype').append('<span class="hover"></span>'); $('.hover').css('opacity', 0); $('.hover').parent().hover(function() { $('.hover', this).stop().animate({ 'opacity': 1 }, fadeSpeed) }, function() { $('.hover', this).stop().animate({ 'opacity': 0 }, fadeSpeed) }); }); $(function() {
var fadeSpeed = ($.browser.safari ? 600 : 450);
$('#logotype').append('<span class="hover"></span>');
$('.hover').css('opacity', 0);
$('.hover').parent().hover(function() {
$('.hover', this).stop().animate({
'opacity': 1
},
fadeSpeed)
},
function() {
$('.hover', this).stop().animate({
'opacity': 0
},
fadeSpeed)
});
});
這段JS很清楚的描述了該效果的實(shí)現(xiàn)原理:首先在鏈接中創(chuàng)建一個(gè)class為hover的span(這個(gè)span是鼠標(biāo)放到連接上時(shí)的現(xiàn)實(shí)效果),并且將其透明度設(shè)置為0,然后當(dāng)鼠標(biāo)移到連接上時(shí),將該span的透明逐漸調(diào)整為1,這樣上面的span就會覆蓋a的默認(rèn)效果,這樣就實(shí)現(xiàn)我們的動畫效果。
基于jQuery實(shí)現(xiàn)的仿flash菜單效果
您可能感興趣的文章:
- jQuery實(shí)現(xiàn)Flash效果上下翻動的中英文導(dǎo)航菜單代碼
- jQuery仿Flash上下翻動的中英文導(dǎo)航菜單實(shí)例
- 超炫的jquery仿flash導(dǎo)航欄特效
- 基于jquery1.4.2的仿flash超炫焦點(diǎn)圖播放效果
- 基于jQuery的仿flash的廣告輪播代碼
- 基于jQuery的仿flash的廣告輪播
- 基于Jquery的仿照flash放大圖片效果代碼
- jquery實(shí)現(xiàn)仿Flash的橫向滑動菜單效果代碼
- jquery+easeing實(shí)現(xiàn)仿flash的載入動畫
- flash+jQuery實(shí)現(xiàn)可關(guān)閉及重復(fù)播放的壓頂廣告
- php+flash+jQuery多圖片上傳源碼分享
- jQuery模擬完美實(shí)現(xiàn)經(jīng)典FLASH導(dǎo)航動畫效果【附demo源碼下載】
相關(guān)文章
jquery img src 獲取實(shí)現(xiàn)代碼
利用jquery 取得IMG src的問題,有需要的朋友可以參考下。2009-05-05方便實(shí)用的jQuery checkbox復(fù)選框全選功能簡單實(shí)例
這篇文章介紹了jQuery checkbox復(fù)選框全選功能的代碼實(shí)例,有需要的朋友可以參考一下2013-10-10jquery 動態(tài)增加刪除行的簡單實(shí)例(推薦)
下面小編就為大家?guī)硪黄猨query 動態(tài)增加刪除行的簡單實(shí)例(推薦)。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2016-10-10jQuery實(shí)現(xiàn)錨點(diǎn)scoll效果實(shí)例分析
這篇文章主要介紹了jQuery實(shí)現(xiàn)錨點(diǎn)scoll效果,實(shí)例分析了錨點(diǎn)scoll效果的實(shí)現(xiàn)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-03-03基于Jquery和html5實(shí)現(xiàn)炫酷的3D焦點(diǎn)圖動畫
這篇文章主要介紹了基于Jquery和html5實(shí)現(xiàn)炫酷的3D焦點(diǎn)圖動畫的相關(guān)資料,焦點(diǎn)圖中的圖片利用了CSS3的相關(guān)特性實(shí)現(xiàn)圖片傾斜效果,從而讓圖片出現(xiàn)3D的視覺效果,感興趣的小伙伴們可以參考一下2016-03-03