JavaScript模擬實(shí)現(xiàn)網(wǎng)易云輪播效果_第1頁
JavaScript模擬實(shí)現(xiàn)網(wǎng)易云輪播效果_第2頁
JavaScript模擬實(shí)現(xiàn)網(wǎng)易云輪播效果_第3頁
JavaScript模擬實(shí)現(xiàn)網(wǎng)易云輪播效果_第4頁
JavaScript模擬實(shí)現(xiàn)網(wǎng)易云輪播效果_第5頁
已閱讀5頁,還剩2頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

第JavaScript模擬實(shí)現(xiàn)網(wǎng)易云輪播效果/*這個(gè)url地址需要根據(jù)img圖片的顯示來改變的*/

background-image:url(/j-TpUI1sHtMz0SRzu6L_Ig==/109951167232808852.jpgimageViewblur=40x20);

background-repeat:no-repeat;

background-size:100%;

.right,

.left{

width:80px;

height:120px;

position:absolute;

top:210px;

right:-80px;

.left{

left:-80px;

.rightimg,

.leftimg{

position:absolute;

top:25px;

left:15px;

width:50px;

height:70px;

.left:hover,

.right:hover{

background-color:rgba(0,0,0,0.5);

cursor:pointer;

width:600px;

height:100px;

position:absolute;

bottom:-20px;

left:340px;

ulli{

float:left;

margin-left:100px;

list-style:disc;

color:rgb(239,232,232);

font-size:50px;

ul.there{

z-index:2;

color:rgb(237,8,8);

ulli:hover{

color:red

width:1200px;

height:500px;

display:none;

.current{

display:block;

}

window.onload=function(){

//定時(shí)器,自動(dòng)改變圖片以及背景圖以及小圓圈

vartimer=window.setInterval(fun,[3000])

functionfun(){

for(i=0;ias.length;i++){

if(as[i].getAttribute('class')=='current'){

flag=i

//如果flag=as.length-1;那么就讓flag=0的a的類變?yōu)閏urrent,如果flagas.length-1,那么就讓flag+1的a的class變?yōu)閏urrent

if(flag==as.length-1){

//排他思想

for(i=0;ias.length;i++){

as[i].classList.remove('current')

lis[i].classList.remove('there')

as[0].classList.add('current')

lis[0].classList.add('there')

e=0

if(flagas.length-1){

for(i=0;ias.length;i++){

as[i].classList.remove('current')

lis[i].classList.remove('there')

as[flag+1].classList.add('current')

lis[flag+1].classList.add('there')

e=flag+1

fn(e)

timer=setInterval(fun,[3000])

//點(diǎn)擊的時(shí)候需要先把定時(shí)器關(guān)閉

//應(yīng)該時(shí)根據(jù)img圖片(直接根據(jù)a鏈接吧)的數(shù)量來動(dòng)態(tài)生成li

varas=document.querySelectorAll('a')

varul=document.querySelector('ul')

varnav=document.querySelector('.nav')

for(i=0;ias.length;i++){

//創(chuàng)建元素

varli=document.createElement('li')

ul.appendChild(li)

//添加元素

//給按鈕添加點(diǎn)擊事件

varflag

varleft=document.querySelector('.left')

varright=document.querySelector('.right')

varlis=document.querySelectorAll('li')

lis[0].classList.add('there')

console.log(lis);

left.addEventListener('click',function(){

window.clearInterval(timer)

//左邊按鈕按下一次,圖片往左邊變化一張,相當(dāng)于要獲得當(dāng)前顯示的a是第幾個(gè)

//對(duì)所有的as進(jìn)行遍歷,看那個(gè)a的class類為current,然后獲得這個(gè)編號(hào)

//i不能用來索引

//還要讓對(duì)應(yīng)的li添加there這個(gè)類名

for(i=0;ias.length;i++){

if(as[i].getAttribute('class')=='current'){

flag=i

//如果flag=0;那么就讓flag=as.length的a的類變?yōu)閏urrent,如果flag0,那么就讓flag-1的a的class變?yōu)閏urrent

if(flag==0){

//排他思想

for(i=0;ias.length;i++){

as[i].classList.remove('current')

lis[i].classList.remove('there')

as[as.length-1].classList.add('current')

lis[as.length-1].classList.add('there')

e=as.length-1

if(flag0){

for(i=0;ias.length;i++){

as[i].classList.remove('current')

lis[i].classList.remove('there')

as[flag-1].classList.add('current')

lis[flag-1].classList.add('there')

e=flag-1

fn(e)

timer=setInterval(fun,[3000])

//類似的添加右邊按鈕的點(diǎn)擊事件

right.addEventListener('click',function(){

window.clearInterval(timer)

//左邊按鈕按下一次,圖片往右邊變化一張,相當(dāng)于要獲得當(dāng)前顯示的a是第幾個(gè)

//對(duì)所有的as進(jìn)行遍歷,看那個(gè)a的class類為current,然后獲得這個(gè)編號(hào)

//i不能用來索引

//還要讓對(duì)應(yīng)的li添加there這個(gè)類名

for(i=0;ias.length;i++){

if(as[i].getAttribute('class')=='current'){

flag=i

//如果flag=as.length-1;那么就讓flag=0的a的類變?yōu)閏urrent,如果flagas.length-1,那么就讓flag+1的a的class變?yōu)閏urrent

if(flag==as.length-1){

//排他思想

for(i=0;ias.length;i++){

as[i].classList.remove('current')

lis[i].classList.remove('there')

as[0].classList.add('current')

lis[0].classList.add('there')

e=0

if(flagas.length-1){

for(i=0;ias.length;i++){

as[i].classList.remove('current')

lis[i].classList.remove('there')

as[flag+1].classList.add('current')

lis[flag+1].classList.add('there')

e=flag+1

fn(e)

timer=setInterval(fun,[3000])

//現(xiàn)在再給下面的小圓圈添加點(diǎn)擊事件

//當(dāng)按下小圓圈的時(shí)候獲得this,那么要獲得是第幾個(gè)小圓圈產(chǎn)生事件,需要自定義屬性一個(gè)編號(hào)。然后用這個(gè)編號(hào)去設(shè)置as[]的類

//自定義屬性

for(i=0;ilis.length;i++){

lis[i].setAttribute('index',i)

//添加事件,因?yàn)橐o每個(gè)小圓圈添加點(diǎn)擊事件,不如直接使用事件委托,將事件監(jiān)聽器設(shè)置再ul上面,利用冒泡原理委托到li上

ul.addEventListener('click',function(e){//為了全局性,直接使用flag

window.clearInterval(timer)

flag=(e.target.getAttribute('index'));

if(flag){

for(i=0;ias.length;i++){

as[i].classList.remove('current')

lis[i].classList.remove('there')

as[flag].classList.add('current')

lis[flag].classList.add('there')

e=flag

fn(e)

timer=setInterval(fun,[3000])

//根據(jù)flag的值去改變box的url

functionfn(e){

if(e==0){

nav.style.backgroundImage='url(/j-TpUI1sHtMz0SRzu6L_Ig==/109951167232808852.jpgimageViewblur=40x20)'

if(e==1){

nav.style.backgroundImage='url(/Q-GYxr6Opgmveo7cTulcOw==/109951167232940234.jpgimageViewblur=40x20)'

if(e==2){

nav.style.backgroundImage='

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔