国产亚洲精品福利在线无卡一,国产精久久一区二区三区,亚洲精品无码国模,精品久久久久久无码专区不卡

當(dāng)前位置: 首頁 > news >正文

婁底網(wǎng)站建設(shè)的話術(shù)北京seo運(yùn)營推廣

婁底網(wǎng)站建設(shè)的話術(shù),北京seo運(yùn)營推廣,廈門網(wǎng)站建設(shè)的公司,做網(wǎng)站開發(fā)怎么接單前端:HTMLCSSJavaScript實(shí)現(xiàn)輪播圖2 1. 和之前版本的區(qū)別2. 實(shí)現(xiàn)原理3. 針對上述的改進(jìn)3. 參考代碼 1. 和之前版本的區(qū)別 之前發(fā)布的那篇關(guān)于輪播圖的文章在這:前端:HTMLCSSJavaScript實(shí)現(xiàn)輪播圖,只能說存在問題吧!比…

前端:HTML+CSS+JavaScript實(shí)現(xiàn)輪播圖2

        • 1. 和之前版本的區(qū)別
        • 2. 實(shí)現(xiàn)原理
        • 3. 針對上述的改進(jìn)
        • 3. 參考代碼

1. 和之前版本的區(qū)別

之前發(fā)布的那篇關(guān)于輪播圖的文章在這:前端:HTML+CSS+JavaScript實(shí)現(xiàn)輪播圖,只能說存在問題吧!比如2、3實(shí)現(xiàn)效果是用了兩個(gè)定時(shí)器實(shí)現(xiàn)的,雖然也達(dá)到了那種效果,但是從一些方面來說總有點(diǎn)繁瑣吧!比如,在一定時(shí)間內(nèi)圖片移動像素的計(jì)算等?,F(xiàn)在這個(gè)不需要計(jì)算,直接用一個(gè)定時(shí)器即可實(shí)現(xiàn),我想說現(xiàn)在這個(gè)版本和各位在瀏覽器上看到那種效果實(shí)現(xiàn)原理應(yīng)該差不多。

請?zhí)砑訄D片描述
雖然沒有給出相應(yīng)的點(diǎn)擊事件哈!

2. 實(shí)現(xiàn)原理

利用相對定位relative、絕對定位absolute、定時(shí)器transition
結(jié)合relative、absolute來進(jìn)行圖片布局,用定時(shí)器來實(shí)現(xiàn)圖片輪播間隔效果,用transition來實(shí)現(xiàn)每張圖片移動過渡效果。
在這里插入圖片描述
初始實(shí)現(xiàn)效果如上,這不符合我們想要的那種效果,這種是通過定時(shí)器每隔幾秒變化每張圖片的left的值的效果。這并不怎么美觀,因?yàn)閳D片過渡效果并不符合我們的要求,但是如果顯示的有多張圖片,那么倒還不錯(cuò),如下:
在這里插入圖片描述

3. 針對上述的改進(jìn)

在這里插入圖片描述
就是把所有圖片從左到右進(jìn)行排列,外層用一個(gè)標(biāo)簽元素包裹,每隔一段時(shí)間變換外層的標(biāo)簽元素的left屬性值。

3. 參考代碼

這個(gè)是需要改進(jìn)的代碼哈!
main.html

<!DOCTYPE html>
<html>
<head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><title></title><link rel="stylesheet" href="./main.css">
</head>
<body><div class="main"></div>
</body>
<script type="text/javascript" src="main.js"></script>
</html>

main.css

*{padding: 0;margin: 0;
}ul{list-style: none;
}.main{width: 500px;height: 300px;margin: 0 auto;position: relative;
}.dot{height: 10px;position: absolute;bottom: 20px;left: 50%;transform: translateX(-50%);
}.dot span{height: 100%;float: left;width: 10px;border-radius: 50%;margin-left: 10px;cursor: pointer;
}.dot span:first-child{margin-left: 0;
}.red{background-color: red;
}.white{background-color: white;
}.main ul{position: relative;height: 100%;width: 100%;overflow-x: hidden;
}.main ul li{position: absolute;top: 0;transition: all 0.3s;width: 100%;height: 100%;
}.main ul li img{width: 100%;
}

main.js

// 輸入圖片鏈接數(shù)組
const img_arr = ['https://i0.hdslb.com/bfs/banner/627984a9617a35c7e4366e0c74baf29ef3aa96ae.png@976w_550h_1c_!web-home-carousel-cover.avif','https://i0.hdslb.com/bfs/banner/3464f3b055107b2b54b9443e02c43448c0915866.png@976w_550h_1c_!web-home-carousel-cover.avif','https://i0.hdslb.com/bfs/banner/ff7d11c786ddd45c218696c3c6b19c69a71883d7.jpg@976w_550h_1c_!web-home-carousel-cover.avif','https://i0.hdslb.com/bfs/sycp/creative_img/202311/74214ce12c94ba104322e2be463ec6f7.jpg@976w_550h_1c_!web-home-carousel-cover.avif'
];const mainEle = document.querySelector('.main');
var _htmlStr = '';
img_arr.forEach(function(ele){_htmlStr += `<li><img src="${ele}"></li>`
})var _htmlStr2 = '';
for(let i=0;i<img_arr.length;i++){_htmlStr2 += '<span></span>'
}var _htmlStr2 = `<div class="dot">${_htmlStr2}</div>`;
_htmlStr = `<ul>${_htmlStr}</ul>${_htmlStr2}`;mainEle.innerHTML = _htmlStr;const img_width = 500;const elements = document.querySelectorAll('.main ul li');
const elements2 = document.querySelectorAll('.dot span');
elements.forEach(function(ele,index){ele.style.left = index * img_width + 'px';
})elements2.forEach(function(ele,index){if(index == 0){ele.className = 'red';}else{ele.className =  'white';}
})function left(){elements.forEach(function(ele,index){let left_v = parseFloat(ele.style.left);if(left_v - img_width < 0){ele.style.left = (elements.length - 1) * img_width + 'px';}else{ele.style.left = left_v - img_width + 'px';}if(left_v - img_width == 0){elements2[index].className = 'red';}else{elements2[index].className = 'white';}})
}var timer = setInterval(left,2000);

這個(gè)是改進(jìn)版本
main.html

<!DOCTYPE html>
<html>
<head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><title></title><link rel="stylesheet" href="./main.css">
</head>
<body><div class="main"><div class="pre_ul" id="main"><ul><li><img src="https://i1.hdslb.com/bfs/archive/da52b26129a84aa316383d53e596d3f89c708294.jpg@672w_378h_1c_!web-home-common-cover.avif" alt=""></li><li><img src="https://i0.hdslb.com/bfs/archive/6df10d7e0834f8511ea620dbfe6bfc7b1eabdab2.jpg@672w_378h_1c_!web-home-common-cover.avif" alt=""></li><li><img src="https://i0.hdslb.com/bfs/archive/47338bc6056b6bbc906155590c6e201ae5dffee8.jpg@672w_378h_1c_!web-home-common-cover.avif" alt=""></li></ul></div><div class="dot" id="main"><span class="red"></span><span class="white"></span><span class="white"></span></div></div>
</body>
<script type="text/javascript" src="main.js"></script>
</html>

main.css

*{margin: 0;padding: 0;
}ul{list-style: none;
}.main{width: 500px;height: 300px;position: relative;margin: 0 auto;overflow-x: hidden;
}.main .dot{position: absolute;bottom: 8%;left: 50%;transform: translateX(-50%);height: 12px;z-index: 2;
}.dot span{float: left;height: 100%;width: 12px;border-radius: 50%;cursor: pointer;margin-left: 8px;
}.dot span:first-child{margin-left: 0;
}.white{background-color: white;
}.red{background-color: red;
}.main .pre_ul{height: 100%;position: absolute;top: 0;left: 0;transition: all 0.5s;z-index: 1;
}.main .pre_ul ul{width: 100%;height: 100%;position: relative;overflow-x: hidden;
}.main .pre_ul ul li{height: 100%;position: absolute;top: 0;left: 0;
}.main .pre_ul ul li img{width: 100%;
}

main.js

const img_width = 500;
// 圖片最大寬度
const eles = document.querySelectorAll('.pre_ul ul li');
const pre_ul_ele = document.querySelector('.pre_ul');
const dots = document.querySelectorAll('.dot span');
const n = eles.length;
pre_ul_ele.style.left = 0;
pre_ul_ele.style.width = n * img_width + 'px';
eles.forEach(function(ele,index){ele.style.width = img_width + 'px';ele.style.left = index * img_width + 'px';
})function clear_red(){dots.forEach(function(ele,index){ele.className = 'white';})
}var start_index = 0;function left(){pre_ul_ele.style.transition = 'all 0.5s';let left_v = parseInt(pre_ul_ele.style.left);pre_ul_ele.style.left = left_v - 500 + 'px';clear_red();start_index = (start_index+1)%n;dots[start_index].className = 'red';if(left_v - 500 == -n*img_width){pre_ul_ele.style.left = 0;}
}var timer1 = setInterval(left,2000);

注:上述代碼沒有給出點(diǎn)擊按鈕變化圖片特效,想實(shí)現(xiàn)的讀者可以去看看上述第一個(gè)關(guān)于實(shí)現(xiàn)輪播圖的版本哈!

http://aloenet.com.cn/news/32533.html

相關(guān)文章:

  • 網(wǎng)站建設(shè)基礎(chǔ)大綱文案軟文推廣有哪些
  • 網(wǎng)站開發(fā)用的那些語言怎么在百度發(fā)布自己的文章
  • 花店網(wǎng)站建設(shè)環(huán)境分析百度搜索什么關(guān)鍵詞能搜到網(wǎng)站
  • 午夜做網(wǎng)站營銷網(wǎng)站的宣傳、推廣與運(yùn)作
  • 淘寶站內(nèi)推廣方式有哪些班級優(yōu)化大師使用心得
  • 許昌做網(wǎng)站漢獅網(wǎng)絡(luò)青島seo關(guān)鍵詞優(yōu)化公司
  • 網(wǎng)上建站賺錢微信公眾號推廣軟文案例
  • 西安微信公眾號制作seo優(yōu)化快速排名
  • 網(wǎng)站建設(shè) 中國聯(lián)盟網(wǎng)百度網(wǎng)頁版登錄首頁
  • 怎么把網(wǎng)站提交百度的推廣廣告
  • 模板企業(yè)快速建站關(guān)鍵詞推廣效果分析
  • 青島商業(yè)網(wǎng)站建設(shè)今日油價(jià)92汽油
  • 韓國網(wǎng)站設(shè)計(jì)風(fēng)格cctv 13新聞?lì)l道
  • 800元做網(wǎng)站哪里做網(wǎng)絡(luò)推廣
  • wordpress所有頁面溫州網(wǎng)站建設(shè)優(yōu)化
  • 做食品網(wǎng)站需要什么條件品牌廣告策劃方案
  • 訪問阿里云主機(jī)網(wǎng)站免費(fèi)的個(gè)人網(wǎng)站怎么做
  • 網(wǎng)站設(shè)計(jì)點(diǎn)評廣州seo成功案例
  • 西安做網(wǎng)站seo網(wǎng)站seo快速排名優(yōu)化
  • 17做網(wǎng)站廣州沙河地址東莞網(wǎng)站推廣優(yōu)化網(wǎng)站
  • b站網(wǎng)頁入口免費(fèi)不收費(fèi)搜索引擎廣告推廣
  • 做網(wǎng)站服務(wù)器怎么用百度推廣關(guān)鍵詞匹配模式
  • 印刷做網(wǎng)站網(wǎng)上接單seo網(wǎng)站排名優(yōu)化工具
  • 做網(wǎng)站設(shè)計(jì)制作的百度網(wǎng)站禁止訪問怎么解除
  • 知名網(wǎng)站建設(shè)加工百度關(guān)鍵詞熱度
  • 重慶網(wǎng)絡(luò)營銷與網(wǎng)絡(luò)廣告百度網(wǎng)盤seo優(yōu)化
  • 南潯做網(wǎng)站推廣普通話標(biāo)語
  • 嘉興網(wǎng)站建設(shè)服務(wù)蘭州網(wǎng)絡(luò)推廣推廣機(jī)構(gòu)
  • 網(wǎng)站升級頁面連接設(shè)置谷歌seo引擎優(yōu)化
  • 網(wǎng)站自然排名這么做北京網(wǎng)站建設(shè)制作公司