javascript實(shí)現(xiàn)切割輪播效果
本文實(shí)例為大家分享了javascript實(shí)現(xiàn)切割輪播的具體代碼,供大家參考,具體內(nèi)容如下
效果
代碼
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <script src="js/jquery.min.js"></script> <style> .container{ position: relative; width: 560px; height: 300px; } .container ul{ /*transform-style:preserve-3d;*/ /*transform: rotateX(-30deg) rotateY(21deg);*/ width: 560px; height: 300px; border:2px solid red; list-style-type: none; margin:0; padding:0; } .container ul li{ position: relative; float: left; /*一張圖分作5片,圖的總寬度是560*/ width: 112px; height: 300px; transform-style:preserve-3d; transition:all 0.5s; } .container ul li span{ position: absolute; left:0; top:0; width: 100%; height: 100% } /*以下4個(gè)選擇器設(shè)定立體效果*/ .container ul li span:nth-child(1){ background: yellow; transform:translateZ(150px); } .container ul li span:nth-child(2){ background: pink; transform:translateY(-150px) rotateX(90deg); } .container ul li span:nth-child(3){ background: orange; transform:translateZ(-150px) rotateX(180deg); } .container ul li span:nth-child(4){ background: blue; transform:translateY(150px) rotateX(270deg); } /*//以下4個(gè)選擇器設(shè)定第n個(gè)span的背景圖*/ .container ul li span:nth-child(1){ background: url(images/1.jpg); } .container ul li span:nth-child(2){ background: url(images/2.jpg); } .container ul li span:nth-child(3){ background: url(images/3.jpg); } .container ul li span:nth-child(4){ background: url(images/4.jpg); } /*以下5個(gè)選擇器用于設(shè)定第i個(gè)li的背景定位*/ .container ul li:nth-child(1) span{ background-position: 0px 0px; } .container ul li:nth-child(2) span{ background-position: -112px 0px; } .container ul li:nth-child(3) span{ background-position: -224px 0px; } .container ul li:nth-child(4) span{ background-position: -336px 0px; } .container ul li:nth-child(5) span{ background-position: -448px 0px; } /*.container ul li:nth-child(1) span:nth-child(1){ background: url(images/1.jpg) 0px 0px; } .container ul li:nth-child(2) span:nth-child(1){ background: url(images/1.jpg) -112px 0px; } .container ul li:nth-child(3) span:nth-child(1){ background: url(images/1.jpg) -224px 0px; } .container ul li:nth-child(4) span:nth-child(1){ background: url(images/1.jpg) -336px 0px; } .container ul li:nth-child(5) span:nth-child(1){ background: url(images/1.jpg) -448px 0px; } .container ul li:nth-child(1) span:nth-child(2){ background: url(images/2.jpg) 0px 0px; } .container ul li:nth-child(2) span:nth-child(2){ background: url(images/2.jpg) -112px 0px; }*/ .container span.left, .container span.right{ position: absolute; top:50%; background: rgba(0,0,0,0.3); width: 18px; height: 40px; font-size:25px; font-weight: bold; color:white; text-align: center; line-height: 40px; cursor:pointer; } .container span.left{ left:0; } .container span.right{ right:0; } </style> </head> <body> <div class="container"> <ul> <li> <span></span> <span></span> <span></span> <span></span> </li> <li> <span></span> <span></span> <span></span> <span></span> </li> <li> <span></span> <span></span> <span></span> <span></span> </li> <li> <span></span> <span></span> <span></span> <span></span> </li> <li> <span></span> <span></span> <span></span> <span></span> </li> </ul> <span class="left"><</span> <span class="right">></span> </div> </body> </html> <script> $(function(){ var allowClick = true; var seq = 0; //代表初始的轉(zhuǎn)動(dòng)角度次數(shù) //先給這5個(gè)li的動(dòng)畫效果設(shè)置不同的延時(shí)(delay) //index表示循環(huán)中的索引號(hào),item表示當(dāng)前項(xiàng)(這里是li) $("ul>li").each( function(index,item){ var delay_time = index*0.25; $(item).css({"transition-delay": delay_time + "s"}); } ); //transitionend事件:動(dòng)畫結(jié)束事件 $("ul>li:last-child").on('transitionend',function(){ allowClick = true; //允許點(diǎn)擊 }); // $("span.left").on('click',function(){ //如果allowClick為false,表示此時(shí)還不允許點(diǎn)擊,就直接退出 if(allowClick == false){ return ;} allowClick = false; //如果可以繼續(xù)下去,此時(shí)就會(huì)去執(zhí)行動(dòng)畫,則此刻 //就必須講這個(gè)allowClick設(shè)定為false seq--; var angle = -seq*90; $("ul>li").css({"transform":"rotateX(" + angle + "deg)"}); }); $("span.right").on('click',function(){ //如果allowClick為false,表示此時(shí)還不允許點(diǎn)擊,就直接退出 if(allowClick == false){ return ;} allowClick = false; seq++; var angle = -seq*90; $("ul>li").css({"transform":"rotateX(" + angle + "deg)"}); }); }); </script>
以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
JS簡單實(shí)現(xiàn)文件上傳實(shí)例代碼(無需插件)
注意一下:在chrome瀏覽器下,為了數(shù)據(jù)安全,隱藏的input:file不能trigger “click” 事件。 所以要設(shè)置input:file的透明度達(dá)到隱藏的效果2013-11-11uniapp使用uni-file-picker實(shí)現(xiàn)上傳功能
這篇文章主要介紹了uniapp使用uni-file-picker實(shí)現(xiàn)上傳功能,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2024-07-07js代碼延遲一定時(shí)間后執(zhí)行一個(gè)函數(shù)的實(shí)例
下面小編就為大家?guī)硪黄猨s代碼延遲一定時(shí)間后執(zhí)行一個(gè)函數(shù)的實(shí)例。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-02-02js下拉菜單語言選項(xiàng)簡單實(shí)現(xiàn)
大家對(duì)下拉菜單并不陌生吧,下面為大家介紹下使用js實(shí)現(xiàn)下拉菜單語言選項(xiàng),具體實(shí)現(xiàn)如下,喜歡的朋友可以看看2013-09-09JavaScript 下載鏈接圖片后上傳的實(shí)現(xiàn)
這篇文章主要介紹了JavaScript 下載鏈接圖片后上傳的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2021-03-03JS?限時(shí)限次數(shù)點(diǎn)擊按鈕的實(shí)現(xiàn)思路
這篇文章主要介紹了JS?限時(shí)限次數(shù)點(diǎn)擊按鈕,實(shí)現(xiàn)方法很簡單需要用一個(gè)變量作為計(jì)數(shù),點(diǎn)擊一次,計(jì)數(shù)加一點(diǎn)擊函數(shù)內(nèi)判斷計(jì)數(shù)變量設(shè)置定時(shí)恢復(fù),對(duì)實(shí)例代碼感興趣的朋友一起看看吧2022-03-03微信小程序web-view不支持打開非業(yè)務(wù)域名https?//XXXX?請(qǐng)重新配置的解決辦法
小程序現(xiàn)在日漸成熟,功能也越來越強(qiáng)大,我們今天來一起看看小程序跳轉(zhuǎn)H5頁面的問題,下面這篇文章主要給大家介紹了關(guān)于微信小程序web-view不支持打開非業(yè)務(wù)域名https?//XXXX?請(qǐng)重新配置的解決辦法,需要的朋友可以參考下2022-08-08