欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

js實(shí)現(xiàn)導(dǎo)航欄上下動(dòng)畫(huà)效果

 更新時(shí)間:2022年07月13日 14:32:59   作者:筆尖兒彎彎  
這篇文章主要為大家詳細(xì)介紹了js實(shí)現(xiàn)導(dǎo)航欄上下動(dòng)畫(huà)效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了js實(shí)現(xiàn)導(dǎo)航欄上下動(dòng)畫(huà)的具體代碼,供大家參考,具體內(nèi)容如下

obj.currentStyle[name] getComputedStyle(obj,false)[name],一個(gè)是支持IE 一個(gè)支持FE
完美運(yùn)動(dòng)js插件,能根據(jù)傳進(jìn)來(lái)的值,進(jìn)行匹配,從而得到了理想的運(yùn)動(dòng)效果,也就是運(yùn)行邏輯。
實(shí)現(xiàn)上下動(dòng)畫(huà)動(dòng)畫(huà)效果就是控制元素height的值,通過(guò)不斷的修改該值,就能呈現(xiàn)所謂的動(dòng)畫(huà)效果,這里就需要用到定時(shí)器

定時(shí)器有兩種

重復(fù)不斷的定時(shí)器 setInterval(fn,time);
延時(shí)只在設(shè)定時(shí)間后只出現(xiàn)一次的定時(shí)器 setTimeout(fn,time)
在遍歷傳進(jìn)的每一個(gè)值,需要使用一個(gè)boolean來(lái)控制是否完成解析,解析成功則返回true,結(jié)束定時(shí)器,返回false,知道返回true位置

function getStyle(obj, attr)
{
?? ?if(obj.currentStyle)
?? ?{
?? ??? ?return obj.currentStyle[attr];
?? ?}
?? ?else
?? ?{
?? ??? ?return getComputedStyle(obj, false)[attr];
?? ?}
}
function startMove(obj,json,fnEnd){
?? ?if(obj.timer){
?? ??? ?clearInterval(obj.timer);
?? ?};
?? ?obj.timer=setInterval(function(){
?? ??? ?var bStop = true; //假設(shè)全部找到
?? ??? ?for(var attr in json){
?? ??? ??? ?var icurr = 0;
?? ??? ??? ?if(attr=='opacity'){//匹配key
?? ??? ??? ??? ?icurr=Math.round(parseFloat(getStyle(obj,attr))*100); //獲取元素的屬性值
?? ??? ??? ?}else{
?? ??? ??? ??? ?icurr=parseInt(getStyle(obj,attr));
?? ??? ??? ?};
?? ??? ??? ?var sPeed = (json[attr]-icurr)/8;
?? ??? ??? ?sPeed=sPeed>0?Math.ceil(sPeed):Math.floor(sPeed);
?? ??? ??? ?if(attr=='opacity'){
?? ??? ??? ??? ?obj.style.filter="alpha(opacity:"+(icurr+sPeed)+")";
?? ??? ??? ??? ?obj.style.opacity=(icurr+sPeed)/100;
?? ??? ??? ?}else{
?? ??? ??? ??? ?obj.style[attr]=icurr+sPeed+'px';
?? ??? ??? ?}
?? ??? ??? ?if(icurr!=json[attr]){
?? ??? ??? ??? ?bStop=false;
?? ??? ??? ?}
?? ??? ?}
?? ??? ?if(bStop){
?? ??? ??? ?clearInterval(obj.timer);
?? ??? ??? ?if(fnEnd){
?? ??? ??? ??? ?fnEnd();
?? ??? ??? ?}
?? ??? ?}
?? ?},30);
}
// alert('dffe');

html布局

<!DOCTYPE html>
<html lang="zh">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<meta http-equiv="X-UA-Compatible" content="ie=edge">
	<link rel="stylesheet" type="text/css" href="css/common.css" />
	<script src="js/move.js"></script>
	<script src="js/common.js"></script>
	<title></title>
</head>
<body>
<div id="box">
	<div><a href="javascript:;" class="a01"></a><em>關(guān)于</em><span></span></div>
	<div><a href="javascript:;" class="a02"></a><em>招聘</em><span></span></div>
	<div><a href="javascript:;" class="a04"></a><em>產(chǎn)品</em><span></span></div>
	<div><a href="javascript:;" class="a03"></a><em>公司</em><span></span></div>
</div>	
</body>
</html>

css文件

*{
?? ?margin: 0;
?? ?padding: 0;
}
a{
?? ?text-decoration: none;
}
body{
?? ?background-color: #c1c1c1;
}
#box{
?? ?width: 880px;
?? ?margin: 100px auto;
?? ?overflow: hidden;
}
#box div{
?? ?width: 200px;
?? ?height: 100px;
?? ?float: left;
?? ?overflow: hidden;
?? ?position: relative;
}
#box div a{
?? ?position: absolute;
?? ?left: 0;
?? ?top: 0;
?? ?width: 200px;
?? ?height: 100px;
?? ?display: block;
?? ?/* background-color: red; */
background: url(../images/1.jpg) no-repeat;
}
#box div span{
?? ?display: block;
?? ?width: 200px;
?? ?height: 100px;
?? ?position: absolute;
?? ?background: url(../images/window.png) left top repeat-x;
}
#box div em{
?? ?display: block;
?? ?width: 100%;
?? ?height: 100%;
?? ?background-color: #999;
?? ?position: absolute;
?? ?text-align: center;
?? ?line-height: 100px;
?? ?font-family: Verdana;
?? ?font-style: normal;
?? ?font-size: 30px;
?? ?color: white;
?? ?text-shadow: 2px 1px 4px black;
?? ?top: 0;
}
#box div a.a01{
?? ??? ?/* background: url(../images/1.jpg) 0 5px no-repeat; */
?? ?background-position: 0 5px;
}
#box div a.a02{
?? ??? ?/* background: url(../images/1.jpg) 0 5px no-repeat; */
?? ?background-position: -200px 5px;
}
#box div a.a03{
?? ??? ?/* background: url(../images/1.jpg) 0 5px no-repeat; */
?? ?background-position: -400px 5px;
}
#box div a.a04{
?? ??? ?/* background: url(../images/1.jpg) 0 5px no-repeat; */
?? ?background-position: -600px 5px;
}

window.οnlοad=fn

window.onload=function(){
?? ?var oDiv = document.getElementById('box');
?? ?var aDiv = oDiv.getElementsByTagName('div');
?? ?var aEm = oDiv.getElementsByTagName('em');
?? ??? ?var aEm = oDiv.getElementsByTagName('em');
?? ?for(var i=0;i<aDiv.length;i++)
?? ??? ?{
?? ??? ??? ?aDiv[i].index = i;
?? ??? ??? ?aDiv[i].onmouseover = function()
?? ??? ??? ?{
?? ??? ??? ??? ?startMove(aEm[this.index],{top:-aEm[this.index].offsetHeight})
?? ??? ??? ?}
?? ??? ??? ?aDiv[i].onmouseout = function()
?? ??? ??? ?{
?? ??? ??? ??? ?startMove(aEm[this.index],{top:0})
?? ??? ??? ?}
?? ??? ?}
}

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • javascript實(shí)現(xiàn)簡(jiǎn)單小鋼琴有聲彈奏效果

    javascript實(shí)現(xiàn)簡(jiǎn)單小鋼琴有聲彈奏效果

    用HTML5+javascript實(shí)現(xiàn)的小鋼琴,按下鋼琴鍵上的相應(yīng)字母用或用鼠標(biāo)點(diǎn)擊鋼琴鍵發(fā)聲,javascript代碼包含了對(duì)鼠標(biāo)按下、移動(dòng)和松開(kāi),以及鍵盤按下的事件監(jiān)聽(tīng)
    2024-02-02
  • 詳解JS對(duì)象遍歷的順序問(wèn)題

    詳解JS對(duì)象遍歷的順序問(wèn)題

    你知不知道JS對(duì)象遍歷順序,本文就來(lái)詳細(xì)的介紹了一下JS對(duì)象遍歷順序問(wèn)題,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-08-08
  • 基于JS編寫(xiě)一個(gè)看字說(shuō)顏色小游戲

    基于JS編寫(xiě)一個(gè)看字說(shuō)顏色小游戲

    這篇文章主要為大家分享了一個(gè)看字說(shuō)顏色的小游戲,游戲是利用JS語(yǔ)言編寫(xiě)實(shí)現(xiàn)的,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以學(xué)習(xí)一下
    2022-04-04
  • JS實(shí)現(xiàn)分頁(yè)導(dǎo)航效果

    JS實(shí)現(xiàn)分頁(yè)導(dǎo)航效果

    這篇文章主要為大家詳細(xì)介紹了JS實(shí)現(xiàn)動(dòng)態(tài)頁(yè)碼及分頁(yè)導(dǎo)航,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-02-02
  • 學(xué)習(xí)JavaScript鼠標(biāo)響應(yīng)事件

    學(xué)習(xí)JavaScript鼠標(biāo)響應(yīng)事件

    這篇文章主要帶領(lǐng)大家學(xué)習(xí)JavaScript鼠標(biāo)響應(yīng)事件,為大家分享了一個(gè)簡(jiǎn)單的鼠標(biāo)模擬案例,感興趣的小伙伴們可以參考一下
    2015-12-12
  • 使用JS實(shí)現(xiàn)導(dǎo)航切換時(shí)高亮顯示的示例講解

    使用JS實(shí)現(xiàn)導(dǎo)航切換時(shí)高亮顯示的示例講解

    今天小編就為大家分享一篇使用JS實(shí)現(xiàn)導(dǎo)航切換時(shí)高亮顯示的示例講解,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2018-08-08
  • JS實(shí)現(xiàn)瀏覽器狀態(tài)欄文字從右向左彈出效果代碼

    JS實(shí)現(xiàn)瀏覽器狀態(tài)欄文字從右向左彈出效果代碼

    這篇文章主要介紹了JS實(shí)現(xiàn)瀏覽器狀態(tài)欄文字從右向左彈出效果,涉及JavaScript結(jié)合時(shí)間函數(shù)遍歷字符串及動(dòng)態(tài)改變狀態(tài)欄顯示效果的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
    2015-10-10
  • js解決軟鍵盤遮擋輸入框的問(wèn)題分享

    js解決軟鍵盤遮擋輸入框的問(wèn)題分享

    下面小編就為大家推薦一篇js解決軟鍵盤遮擋輸入框的問(wèn)題分享,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2017-12-12
  • 淺談JavaScript中的parseInt()的妙用

    淺談JavaScript中的parseInt()的妙用

    本文主要介紹了JavaScript中的parseInt()的妙用,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2021-07-07
  • webpack2.0配置postcss-loader的方法

    webpack2.0配置postcss-loader的方法

    本篇文章主要介紹了webpack2.0配置postcss-loader的方法,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-08-08

最新評(píng)論