>jquer和封裝的運動函數(shù)對比 #parent{ margin:500px 500px 0 500px; position: relative; width: 35%; height: 500px; } #parent d..."/>
溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

jquer和封裝的運動函數(shù)對比

發(fā)布時間:2020-07-21 01:07:58 來源:網(wǎng)絡 閱讀:360 作者:沉迷學習中 欄目:開發(fā)技術

<!doctype html>

<html lang="en">

<head>

<meta charset="UTF-8">

<title>圖片切換----->>

jquer和封裝的運動函數(shù)對比

</title>

<style type="text/css">

#parent{

margin:500px 500px 0 500px;

position: relative;

width: 35%;

height: 500px;

}

#parent div{

position: absolute;

}

#parent span{

position: absolute;

color:green;

font-size: 136px;

z-index: 99;

cursor: pointer;

}

</style>

<script type="text/javascript" src="jquery.js"></script>

<script type="text/javascript">

window.onload=function(){

var parent = document.getElementById("parent");

var span =parent.getElementsByTagName("span");


var son_div = parent.getElementsByTagName("div");

var arr   =[];

for(var i=0;i<son_div.length;i++){

var img = son_div[i].getElementsByTagName("img")[0];

arr.push({

'top'     : getStyle(son_div[i],'top'),

'left'    : getStyle(son_div[i],'left'),

'zIndex'  : getStyle(son_div[i],'zIndex'),

'opacity' : getStyle(son_div[i],'opacity'),

'width'   : getStyle(img,'width'),

'height'  : getStyle(img,'height')

  });

}

console.log(arr);

//左

span[0].onclick=function(){

arr.push(arr[0]);

arr.shift();

for(var i=0;i<arr.length;i++){

var img1 = son_div[i].getElementsByTagName("img")[0];

son_div[i].style.zIndex=arr[i].zIndex;


startMove(son_div[i],{

'top':arr[i].top,

'left':arr[i].left,

'opacity': arr[i].opacity*100

});

startMove(img1,{

'width': arr[i].width,

'height':arr[i].height,

});

/*

$(son_div[i]).animate({

'top':arr[i].top,

'left':arr[i].left,

'opacity':arr[i].opacity

},300)

$(img1).animate({

'width': arr[i].width,

'height':arr[i].height,

},300)

*/

}

}

//右

span[1].onclick=function(){

arr.unshift(arr[arr.length-1]);

arr.pop();

for(var i=0;i<arr.length;i++){

var img1 = son_div[i].getElementsByTagName("img")[0];

son_div[i].style.zIndex=arr[i].zIndex;

$(son_div[i]).animate({

'top':arr[i].top,

'left':arr[i].left,

'opacity':arr[i].opacity

},300)

$(img1).animate({

'width': arr[i].width,

'height':arr[i].height,

},300)

}


}

}

function startMove(obj,json,endfn){

clearInterval(obj.setTime);

var iCur =0;

obj.setTime=setInterval(function(){

var kaiguan = true;

var dir;

  for(var attr in json){

if(attr=='opacity'){

iCur =Math.round(getStyle(obj,'opacity')*100);

}else{

iCur =parseInt(getStyle(obj,attr));

}

dir = (parseInt(json[attr])-iCur)/8;

dir = dir>0?Math.ceil(dir):Math.floor(dir);

if(iCur!=parseInt(json[attr])){

kaiguan=false;

if(attr=='opacity'){

obj.style.opacity=(iCur+dir)/100;

obj.style.filter='alpha(opacity='+(iCur+dir)+')';

}else{

obj.style[attr]=iCur+dir+'px';

}

}

}

if(kaiguan){

clearInterval(obj.setTime);

//回調(diào)函數(shù)

endfn&&endfn.call(obj);

}

},30);

}


//獲取樣式的值

function getStyle ( obj, attr ){ 

return obj.currentStyle?obj.currentStyle[attr] : getComputedStyle( obj )[attr];

}

</script>

</head>

<body>


<div id="parent">

<span ><</span>

<span >></span>

<div >

<img src="p_w_picpaths/scenery_11.jpg" />

</div>

<div >

<img  src="p_w_picpaths/scenery_13.jpg" />

</div>

<div >

<img  src="p_w_picpaths/scenery_14.jpg" />

</div>

<div >

<img src="p_w_picpaths/scenery_15.jpg" />

</div>

<div >

<img src="p_w_picpaths/scenery_16.jpg" />

</div>

</div>

</body>

</html>


向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權內(nèi)容。

AI