基于JavaScript實(shí)現(xiàn)熔巖燈效果導(dǎo)航菜單
熔巖燈效果 就是鼠標(biāo)移入的時(shí)候,背景跟著滑過去~
兩方法如下:
方法一:兩個(gè)文件,一個(gè)HTML,一個(gè)JS。
HTML源碼,
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!--
<link href="favicon.ico" rel="shortcut icon" type="image/x-icon" />
<link href="favicon.ico" rel="Bookmark" type="image/x-icon" />
-->
<meta name="Generator" content="EditPlus®">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<title>Document</title>
<link href="" rel="stylesheet" />
<style type="text/css">
#nav {
position: relative;
background: #292929;
float: left;
}
#nav li {
float: left;
list-style: none;
border-right: 1px solid #4a4a4a;
border-left: 1px solid black;
}
#nav li a {
color: #e3e3e3;
position: relative;
z-index: 2;
float: left;
font-size: 30px;
font-family: helvetica, arial, sans-serif;
text-decoration: none;
padding: 30px 45px;
}
ul, li {
margin: 0; padding: 0;
}
#blob {
border-right: 1px solid #0059ec;
border-left: 1px solid #0059ec;
position: absolute;
top: 0;
z-index : 1;
background: #0b2b61;
background: -moz-linear-gradient(top, #0b2b61, #1153c0);
background: -webkit-gradient(linear, left top, left bottom, from(#0b2b61), to(#1153c0));
-moz-border-radius: 4px;
-webkit-border-radius: 4px;
-moz-box-shadow: 2px 3px 10px #011331;
-webkit-box-shadow: 2px 3px 10px #011331;
}
</style>
<script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="http://apps.bdimg.com/libs/jqueryui/1.9.2/jquery-ui.min.js"></script>
<script type="text/javascript" src="jquery.spasticNav.js"></script>
</head>
<body>
<ul id="nav">
<li><a href="#">Home</a></li>
<li id="selected"><a href="#">About</a></li>
<li><a href="#">Blog</a></li>
<li><a href="#">Contact</a></li>
</ul>
<script type="text/javascript">
$('#nav').spasticNav();
</script>
</body>
</html>
JS源碼,
(function($) {
$.fn.spasticNav = function(options) {
options = $.extend({
overlap : 15,
speed : 500,
reset : 1500,
color : '#9f1f31',
easing : 'easeOutExpo'
}, options);
return this.each(function() {
var nav = $(this),
currentPageItem = $('#selected', nav),
blob,
reset;
$('<li id="blob"></li>').css({
width : currentPageItem.outerWidth(),
height : currentPageItem.outerHeight() + options.overlap,
left : currentPageItem.position().left,
top : currentPageItem.position().top - options.overlap / 2,
backgroundColor : options.color
}).appendTo(this);
blob = $('#blob', nav);
$('li:not(#blob)', nav).hover(function() {
// mouse over
clearTimeout(reset);
blob.animate(
{
left : $(this).position().left,
width : $(this).width()
},
{
duration : options.speed,
easing : options.easing,
queue : false
}
);
}, function() {
// mouse out
reset = setTimeout(function() {
blob.animate({
width : currentPageItem.outerWidth(),
left : currentPageItem.position().left
}, options.speed)
}, options.reset);
});
}); // end each
};
})(jQuery);
方法二,使用jquery插件 jquery.lavalamp.min.js 實(shí)現(xiàn)。
需要調(diào)用的文件有:jQuery庫,jQuery緩動插件(jquery.easing.min.js),火焰燈效果插件(jquery.lavalamp.min.js)以及一個(gè)ul li列表的樣式文件。
詳情參看:http://www.dhdzp.com/article/102028.htm
插件官網(wǎng)介紹:http://lavalamp.magicmediamuse.com
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- JS無限級導(dǎo)航菜單實(shí)現(xiàn)方法
- AngularJS+Bootstrap3多級導(dǎo)航菜單的實(shí)現(xiàn)代碼
- js+div+css下拉導(dǎo)航菜單完整代碼分享
- JS中用三種方式實(shí)現(xiàn)導(dǎo)航菜單中的二級下拉菜單
- JS 實(shí)現(xiàn)導(dǎo)航菜單中的二級下拉菜單的幾種方式
- JavaScript實(shí)戰(zhàn)之帶收放動畫效果的導(dǎo)航菜單
- ABP框架中導(dǎo)航菜單的使用及JavaScript API獲取菜單的方法
- 原生js和jquery分別實(shí)現(xiàn)橫向?qū)Ш讲藛涡Ч?/a>
- javascript HTML+CSS實(shí)現(xiàn)經(jīng)典橙色導(dǎo)航菜單
- 以JavaScript來實(shí)現(xiàn)WordPress中的二級導(dǎo)航菜單的方法
- JS+CSS實(shí)現(xiàn)另類帶提示效果的豎向?qū)Ш讲藛?/a>
- JS+CSS實(shí)現(xiàn)簡單的二級下拉導(dǎo)航菜單效果
- JS實(shí)現(xiàn)移動端可折疊導(dǎo)航菜單(現(xiàn)代都市風(fēng))
相關(guān)文章
編寫一個(gè)javascript元循環(huán)求值器的方法
這篇文章主要介紹了編寫一個(gè)javascript元循環(huán)求值器的方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-04-04
javascript 初學(xué)教程及五子棋小程序的簡單實(shí)現(xiàn)
下面小編就為大家?guī)硪黄猨avascript 初學(xué)教程及五子棋小程序的簡單實(shí)現(xiàn)。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-07-07
JS中數(shù)據(jù)類型的正確判斷方法實(shí)例
怎么去判斷一個(gè)數(shù)據(jù)屬于哪個(gè)數(shù)據(jù)類型,這個(gè)是很常見的操作,我們一般都會想到typeof和instanceof這兩個(gè)常見的方法,但有時(shí)候這兩種方法并不能滿足我們的需求,下面這篇文章主要給大家介紹了關(guān)于JS中數(shù)據(jù)類型的正確判斷方法,需要的朋友可以參考下2021-08-08
JavaScript實(shí)現(xiàn)輸入框(密碼框)出現(xiàn)提示語
有時(shí)候我們需要在登陸表單有一些提示語言,比如“請輸入用戶名”和“請輸入密碼”等語言,通過本文給大家介紹JavaScript實(shí)現(xiàn)輸入框(密碼框)出現(xiàn)提示語的相關(guān)知識,對js實(shí)現(xiàn)輸入框提示相關(guān)知識感興趣的朋友一起學(xué)習(xí)吧2016-01-01
Bootstrap滾動監(jiān)聽(Scrollspy)插件詳解
滾動監(jiān)聽插件是用來根據(jù)滾動條所處在的位置自動更新導(dǎo)航項(xiàng)目, 顯示導(dǎo)航項(xiàng)目高亮顯示。這篇文章主要介紹了Bootstrap滾動監(jiān)聽(Scrollspy)插件的相關(guān)資料,需要的朋友可以參考下2016-04-04

