中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當前位置: 首頁 > news >正文

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

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

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

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

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

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

請?zhí)砑訄D片描述
雖然沒有給出相應的點擊事件哈!

2. 實現(xiàn)原理

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

3. 針對上述的改進

在這里插入圖片描述
就是把所有圖片從左到右進行排列,外層用一個標簽元素包裹,每隔一段時間變換外層的標簽元素的left屬性值。

3. 參考代碼

這個是需要改進的代碼哈!
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);

這個是改進版本
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);

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

http://www.risenshineclean.com/news/32533.html

相關文章:

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