亚洲精品久久久中文字幕-亚洲精品久久片久久-亚洲精品久久青草-亚洲精品久久婷婷爱久久婷婷-亚洲精品久久午夜香蕉

您的位置:首頁技術(shù)文章
文章詳情頁

js輪播圖之旋轉(zhuǎn)木馬效果

瀏覽:61日期:2024-04-17 09:25:25

本文實例為大家分享了js輪播圖之旋轉(zhuǎn)木馬效果的具體代碼,供大家參考,具體內(nèi)容如下

思路:給定一個數(shù)組,儲存每張圖片的位置,旋轉(zhuǎn)將位置進行替換左旋轉(zhuǎn):將數(shù)組第一個數(shù)據(jù)刪除,然后添加到數(shù)組的最后右旋轉(zhuǎn):將數(shù)組最后一個數(shù)據(jù)刪除,然后添加到數(shù)組的開頭先附上效果圖,再來實現(xiàn)

js輪播圖之旋轉(zhuǎn)木馬效果

接下來就是最主要的,封裝原生js動畫函數(shù)

//封裝函數(shù)獲取任意一個元素的任意屬性的值(兼容ie8)function getStyle(element, attr) { return window.getComputedStyle ? window.getComputedStyle(element, null)[attr] : element.currentStyle[attr];}//封裝js變速動畫function animate(element, json, fn) { //每次啟動定時器之前先停止 clearInterval(element.tmId); element.tmId = setInterval(function () { var flag = true; //遍歷對象中的每個屬性 for (var attr in json) { //執(zhí)行透明度動畫 if (attr == 'opacity') { //獲取當前元素的屬性值 var current = parseInt(getStyle(element, attr)*100); //獲取目標值 var target = json[attr]*100; //移動的步數(shù) var step = (target - current) / 10; step = step > 0 ? Math.ceil(step) : Math.floor(step); //移動后的值 current += step; element.style[attr] = current / 100; } else if (attr == 'zIndex') { //改變層級屬性 element.style[attr] = json[attr]; } else { //獲取當前元素的屬性值 var current = parseInt(getStyle(element, attr)); //獲取目標值 var target = json[attr]; //移動的步數(shù) var step = (target - current) / 10; step = step > 0 ? Math.ceil(step) : Math.floor(step); //移動后的值 current += step; element.style[attr] = current + 'px'; if (current != target) { flag = false; } } } if (flag) { clearInterval(element.tmId); //如果有回調(diào)函數(shù)就調(diào)用 if (fn) fn(); } // 測試 // console.log('目標:' + target + '/當前:' + current + '/步數(shù):' + step); }, 20);}

封裝完函數(shù),剩下的直接調(diào)用就可以了,最后附上旋轉(zhuǎn)木馬完整代碼?

<!DOCTYPE html><html><head lang='en'> <meta charset='UTF-8'> <title>旋轉(zhuǎn)木馬輪播圖</title> <link rel='stylesheet' href='http://www.aoyou183.cn/bcjs/css/css(1).css' rel='external nofollow' /> <script src='http://www.aoyou183.cn/bcjs/common.js'></script> <script> var config = [ { width: 400, top: 20, left: 50, opacity: 0.2, zIndex: 2 },//0 { width: 600, top: 70, left: 0, opacity: 0.8, zIndex: 3 },//1 { width: 800, top: 100, left: 200, opacity: 1, zIndex: 4 },//2 { width: 600, top: 70, left: 600, opacity: 0.8, zIndex: 3 },//3 { width: 400, top: 20, left: 750, opacity: 0.2, zIndex: 2 }//4 ]; window.onload = function () { var flag = true; var list = $query('#slide').getElementsByTagName('li'); function flower() { //1、圖片散開 for (var i = 0; i < list.length; i++) { //設(shè)置每個li的寬,透明度,left,top,zindex animate(list[i], config[i], function () { flag = true; }); } } flower();//初始化調(diào)用函數(shù) //按鈕的顯示與隱藏 $query('#slide').onmouseover = function () { $query('#arrow').style.opacity = '1'; } $query('#slide').onmouseout = function () { $query('#arrow').style.opacity = '0'; } //點擊切換 $query('#arrLeft').onclick = function () { if (flag) { config.unshift(config.pop()); flower(); flag = false; } } $query('#arrRight').onclick = function () { if (flag) { config.push(config.shift()); flower(); flag = false; } } //自動切換 setInterval(function () { config.push(config.shift()); flower(); }, 2000); } </script></head><body><div id='wrap'> <div id='slide'> <ul> <li><a href='http://www.aoyou183.cn/bcjs/14370.html#'><img src='http://www.aoyou183.cn/bcjs/images/slidepic1.jpg' alt=''/></a></li> <li><a href='http://www.aoyou183.cn/bcjs/14370.html#'><img src='http://www.aoyou183.cn/bcjs/images/slidepic2.jpg' alt=''/></a></li> <li><a href='http://www.aoyou183.cn/bcjs/14370.html#' ><img src='http://www.aoyou183.cn/bcjs/images/slidepic3.jpg' alt=''/></a></li> <li><a href='http://www.aoyou183.cn/bcjs/14370.html#'><img src='http://www.aoyou183.cn/bcjs/images/slidepic4.jpg' alt=''/></a></li> <li><a href='http://www.aoyou183.cn/bcjs/14370.html#'><img src='http://www.aoyou183.cn/bcjs/images/slidepic5.jpg' alt=''/></a></li> </ul> <div id='arrow'> <a href='javascript:void(0);' id='arrLeft'></a> <a href='javascript:void(0);' id='arrRight'></a> </div> </div></div></body></html>

精彩專題分享:jQuery圖片輪播 JavaScript圖片輪播 Bootstrap圖片輪播

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網(wǎng)。

標簽: JavaScript
相關(guān)文章:
主站蜘蛛池模板: 国产视频在线观看福利 | 久久这里只有精品免费看青草 | 高清免费a级在线观看国产 高清免费毛片 | 美国美女黄色片 | a级做爰毛片视频免费看 | 欧美性色黄大片一级毛片视频 | 尤物视频在线看 | 精品乱码| 免费www xxx| 亚洲高清在线观看 | 国产精品视频99 | 亚洲欧美日韩中另类在线 | 美国一级黄色片 | 国产在线欧美精品 | 西西444www| 久草资源站在线 | 中国黄色一级片 | 自偷自偷自亚洲首页精品 | 91在线精品中文字幕 | 成人三级毛片 | 亚洲欧美在线播放 | 亚洲国产视频一区 | 精品一区二区国语对白 | 青青青青爽极品在线视频 | 在线看色片 | 国产一二三区在线观看 | 亚洲国产精品日韩高清秒播 | 免费看欧美一级特黄a大片一 | 欧美一区二区三区不卡免费 | 大插香蕉 | 免费观看性生交大片人 | 欧美一级毛片特黄大 | www黄色网| 香蕉在线视频网站 | 成人福利在线视频 | 有码日韩 | 日本久久久久亚洲中字幕 | 欧美一级毛级毛片 | 国产一区二区三区亚洲欧美 | 男女在线观看啪网站 | 国产入口在线观看 |