輪播圖案例

丐版輪播圖

<!DOCTYPE html>
<html lang="zh-cn">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title> 基礎輪播圖 banner 移入移出</title><style>* {margin: 0;padding: 0;}body {display: flex;justify-content: center;}.banner {display: flex;flex-direction: column;align-items: center;justify-content: center;position: relative;width: 500px;box-shadow: 0 0 8px #333;}.slider {display: flex;justify-content: space-around;align-items: center;position: absolute;bottom: 10px;width: 380px;}.slider span {width: 45px;height: 45px;line-height: 45px;background-color: orange;text-align: center;font-size: 20px;color: #fff;border-radius: 50%;cursor: pointer;}.btn-wrap span {user-select: none;position: absolute;top: 0;bottom: 0;margin: auto;width: 40px;height: 85px;line-height: 85px;font-size: 32px;color: #fff;text-align: center;background-color: rgba(0, 0, 0, .4);cursor: pointer;}.btn-wrap span:hover {background-color: rgba(0, 0, 0, .8);}.prev {left: 0;}.next {right: 0;}</style>
</head><body><div class="banner"><img id="pic" src="images/p1.jpg" width="500" height="375" alt="pkq"><div class="slider"><span style="background-color: pink;">1</span><span>2</span><span>3</span><span>4</span></div><div class="btn-wrap"><span class="prev">&lt;</span><span class="next">&gt;</span></div></div><script>var oSlider = document.querySelector('.slider')var aSpan = document.querySelectorAll('.slider span')var oPic = document.querySelector('#pic')var oPrev = document.querySelector('.prev')var oNext = document.querySelector('.next')var index = 0var count = 4oNext.onclick = function () {aSpan[index].style.backgroundColor = 'orange';index++index = index % countoPic.src = `images/p${index + 1}.jpg`aSpan[index].style.backgroundColor = '#543';}oPrev.onclick = function () {aSpan[index].style.backgroundColor = 'orange';index--index = (index +count) % countoPic.src = `images/p${index + 1}.jpg`aSpan[index].style.backgroundColor = '#543';}oSlider.onmouseover = function (e) {if(e.target.tagName === 'SPAN') {aSpan[index].style.backgroundColor = 'orange';oPic.src = `images/p${e.target.innerText}.jpg`e.target.style.backgroundColor = '#543';index = e.target.innerText - 1}}</script>
</body></html>

進階輪播圖

<!DOCTYPE html>
<html lang="zh-cn">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title> 基礎輪播圖 banner 移入移出</title><style>* {margin: 0;padding: 0;}ul {list-style: none;}body {display: flex;justify-content: center;}.banner {display: flex;flex-direction: column;align-items: center;justify-content: center;position: relative;width: 500px;height: 290px;margin-top: 100px;box-shadow: 0 0 12px #333;}.pic li {display: none;position: absolute;top: 0;left: 0;}.pic li.on {display: block;}.pic li img {width: 500px;height: 290px;}.slider {display: flex;justify-content: space-around;align-items: center;position: absolute;bottom: 10px;width: 380px;}.slider span {width: 45px;height: 45px;line-height: 45px;background-color: orange;text-align: center;font-size: 20px;color: #fff;border-radius: 50%;cursor: pointer;}.slider span.active {background-color: pink;}.btn-wrap span {user-select: none;position: absolute;top: 0;bottom: 0;margin: auto;width: 40px;height: 85px;line-height: 85px;font-size: 32px;color: #fff;text-align: center;background-color: rgba(0, 0, 0, .4);cursor: pointer;}.btn-wrap span:hover {background-color: rgba(0, 0, 0, .8);}.prev {left: 0;}.next {right: 0;}</style>
</head>
<body><div class="banner"><ul class="pic"><li class="on bg333 c368"><img src="images/p1.jpg" alt=""></li><li class="bg333 c368"><img src="images/p2.jpg" alt=""></li><li class="bg333 c368"><img src="images/p3.jpg" alt=""></li><li class="bg333 c368"><img src="images/p4.jpg" alt=""></li></ul><div class="slider"></div><div class="btn-wrap"><span class="prev">&lt;</span><span class="next">&gt;</span></div></div><script>var oSlider = document.querySelector('.slider')var oPic = document.querySelector('.pic')var oWrap = document.querySelector('.btn-wrap')var switchWrap = {'prev': function () {switchSlider(function () {index--index = (index +count) % count})},'next': function () {switchSlider(function () {index++index = index % count})}}var index = 0var count = oPic.children.lengthcreateSlider()oWrap.addEventListener('click', function (e) {switchWrap[e.target.className] && switchSlider(switchWrap[e.target.className]())}, false)oSlider.addEventListener('mouseover', function (e) {if(e.target.tagName === 'SPAN') {switchSlider(function () {index = e.target.innerText - 1})}}, false)function switchSlider (callback) {oPic.children[index].classList.remove('on')oSlider.children[index].classList.remove('active')callback && callback() oPic.children[index].classList.add('on')oSlider.children[index].classList.add('active')}function createSlider () {var fragment = document.createDocumentFragment();for(var i = 0; i < count; i++) {var vDom = document.createElement('span')vDom.innerText = i + 1fragment.appendChild(vDom)}fragment.children[0].classList.add('on')oSlider.appendChild(fragment)}</script>
</body></html>

動畫輪播自動播放

<!DOCTYPE html>
<html lang="zh-cn"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title> 輪播圖 </title><style>* {margin: 0;padding: 0;}img {display: block;}ul {list-style: none;}body {display: flex;justify-content: center;}.banner {overflow: hidden;position: relative;width: 500px;box-shadow: 0 0 8px #333;}.pic-list {width: 100%;}.pic-list li {float: left;}.slider {display: flex;justify-content: space-around;align-items: center;position: absolute;bottom: 10px;width: 380px;left: 0;right: 0;margin: auto;}.slider span {width: 45px;height: 45px;line-height: 45px;background-color: orange;text-align: center;font-size: 20px;color: #fff;border-radius: 50%;cursor: pointer;}.btn-wrap span {user-select: none;position: absolute;top: 0;bottom: 0;margin: auto;width: 40px;height: 85px;line-height: 85px;font-size: 32px;color: #fff;text-align: center;background-color: rgba(0, 0, 0, .4);cursor: pointer;}.btn-wrap span:hover {background-color: rgba(0, 0, 0, .8);}.prev {left: 0;}.next {right: 0;}.slider .active {background-color: pink;}</style>
</head><body><div class="banner"><ul class="pic-list"><li><img src="images/1.jpg" alt="" width="500" height="200"></li><li><img src="images/2.jpg" alt="" width="500" height="200"></li><li><img src="images/3.jpg" alt="" width="500" height="200"></li><li><img src="images/4.jpg" alt="" width="500" height="200"></li></ul><div class="slider"></div><div class="btn-wrap"><span class="prev">&lt;</span><span class="next">&gt;</span></div></div><script src="js/common.js"></script><script>var oBanner = $('.banner');var oUl = $('.pic-list');var aPic = $$('.pic-list li');var oBtnWrap = $('.btn-wrap');var oSlider = $('.slider');var aSlider = oSlider.children;var picW = aPic[0].offsetWidth;var picLen = aPic.length;var index = 0;var timer;var tapMap = {'prev': function (e) {move(function () {index--;index = (picLen + index) % picLen;})},'next': function (e) {move(function () {index++;index = index % picLen;})}}init();autoTranslate();function init() {var spanStr = '';var firstClass = '';oUl.style.width = `${picLen * 100}%`;for (var i = 0; i < picLen; i++) {firstClass = ''if (i === 0) {firstClass = 'class="active"';}spanStr += `<span ${firstClass}>${i + 1}</span>`;}oSlider.innerHTML = spanStr;}oBanner.addEventListener('mouseover', function () {clearInterval(timer);}, false);oBanner.addEventListener('mouseout', function () {autoTranslate();}, false)oBtnWrap.addEventListener('click', function (e) {e = e || window.event;if (e.target.tagName.toLowerCase() === 'span') {var btn = e.target;if (tapMap[btn.className] && typeof tapMap[btn.className] === 'function') {tapMap[btn.className](e);}}}, false);oSlider.addEventListener('mouseover', function (e) {e = e || window.event;if (e.target.tagName.toLowerCase() === 'span') {var sliderBtn = e.target;move(function () {index = getElementIdx(sliderBtn);})}}, false);function move(callback) {aSlider[index].classList.remove('active');callback && callback(); aSlider[index].classList.add('active');animate(oUl, {marginLeft: -index * picW + 'px'})}//自動切換 輪播 index++;function autoTranslate() {clearInterval(timer);timer = setInterval(function () {move(function () {index++;index = index % picLen;});}, 1000)}</script>
</body></html>

無縫輪播

<!DOCTYPE html>
<html lang="zh-cn"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title> 輪播圖 </title><style>* {margin: 0;padding: 0;}img {display: block;}ul {list-style: none;}body {display: flex;justify-content: center;}.banner {overflow: hidden;position: relative;width: 500px;box-shadow: 0 0 8px #333;}.pic-list {width: 100%;}.pic-list li {float: left;}.slider {display: flex;justify-content: space-around;align-items: center;position: absolute;bottom: 10px;width: 380px;left: 0;right: 0;margin: auto;}.slider span {width: 45px;height: 45px;line-height: 45px;background-color: orange;text-align: center;font-size: 20px;color: #fff;border-radius: 50%;cursor: pointer;}.btn-wrap span {user-select: none;position: absolute;top: 0;bottom: 0;margin: auto;width: 40px;height: 85px;line-height: 85px;font-size: 32px;color: #fff;text-align: center;background-color: rgba(0, 0, 0, .4);cursor: pointer;}.btn-wrap span:hover {background-color: rgba(0, 0, 0, .8);}.prev {left: 0;}.next {right: 0;}.slider .active {background-color: pink;}</style>
</head><body><div class="banner"><ul class="pic-list"><li><img src="images/1.jpg" alt="" width="500" height="200"></li><li><img src="images/2.jpg" alt="" width="500" height="200"></li><li><img src="images/3.jpg" alt="" width="500" height="200"></li><li><img src="images/4.jpg" alt="" width="500" height="200"></li></ul><div class="slider"></div><div class="btn-wrap"><span class="prev">&lt;</span><span class="next">&gt;</span></div></div><script src="js/common.js"></script><script>var oBanner = $('.banner');var oUl = $('.pic-list');var aPic = $$('.pic-list li');var oBtnWrap = $('.btn-wrap');var oSlider = $('.slider');var aSlider = oSlider.children;var picW = aPic[0].offsetWidth;var picLen = aPic.length + 1;var index = 0;var timer;init();var tapMap = {'prev': function (e) {move(function () {if (index === 0) {index = aPic.length - 1;oUl.style.marginLeft = -index * picW + 'px';}index--;index = (picLen + index) % picLen;});},'next': function (e) {move(function () {if (index === aPic.length - 1) {console.log('我要瞬間調到0 然后慢慢走到1');index = 0;oUl.style.marginLeft = -index * picW + 'px';}index++; //4index = index % picLen; // len 5 4%4});}}function init() {var spanStr = '';var firstClass = '';oUl.style.width = `${picLen * 100}%`;for (var i = 0; i < picLen - 1; i++) {firstClass = ''if (i === 0) {firstClass = 'class="active"';}spanStr += `<span ${firstClass}>${i + 1}</span>`;}oSlider.innerHTML = spanStr;oUl.appendChild(aPic[0].cloneNode(true));aPic = $$('.pic-list li');autoTranslate();}oBanner.addEventListener('mouseover', function () {clearInterval(timer);}, false);oBanner.addEventListener('mouseout', function () {autoTranslate();}, false);oBtnWrap.addEventListener('click', function (e) {e = e || window.event;if (e.target.tagName.toLowerCase() === 'span') {var btn = e.target;if (tapMap[btn.className] && typeof tapMap[btn.className] === 'function') {tapMap[btn.className](e);}}}, false);oSlider.addEventListener('mouseover', function (e) {e = e || window.event;if (e.target.tagName.toLowerCase() === 'span') {var sliderBtn = e.target;move(function () {index = getElementIdx(sliderBtn);})}}, false);function move(callback) {aSlider[index % (aPic.length - 1)].classList.remove('active');callback && callback(); //插入執行 index修改代碼//如果index 為4 我們讓index 變為0  4%4 3%4 2%4aSlider[index % (aPic.length - 1)].classList.add('active');animate(oUl, {marginLeft: -index * picW + 'px'})}//自動切換 輪播 index++;function autoTranslate() {clearInterval(timer);timer = setInterval(function () {tapMap['next']();}, 1000)}</script>
</body></html>

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/diannao/42942.shtml
繁體地址,請注明出處:http://hk.pswp.cn/diannao/42942.shtml
英文地址,請注明出處:http://en.pswp.cn/diannao/42942.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

6000字以上論文參考:基于Java+SpringMvc+Vue技術的實驗室管理系統設計與實現

可參考&#xff1a;基于JavaSpringMvcVue技術的實驗室管理系統設計與實現&#xff08;6000字以上論文參考&#xff09;-CSDN博客 論文參考&#xff1a;

【python】字典、列表、集合綜合練習

1、練習1(字典) 字典dic,dic {‘k1’:‘v1’, ‘k2’: ‘v2’, ‘k3’: [11,22,33]} (1). 請循環輸出所有的key dic {"k1": "v1", "k2": "v2", "k3": [11, 22, 33]} for k in dic.keys():print(k)k1 k2 k3(2). 請循環輸…

2024 WAIC|第四范式胡時偉分享通往AGI之路:行業大模型匯聚成海

7月4日&#xff0c;2024世界人工智能大會&#xff08;WAIC&#xff09;正式開幕。此次大會圍繞核心技術、智能終端、應用賦能等板塊展開&#xff0c;展覽規模、參展企業數均達歷史最高。第四范式受邀參展&#xff0c;集中展示公司十年來在行業大模型產業應用方面的實踐。在當天…

【知網CNKI-注冊安全分析報告】

前言 由于網站注冊入口容易被黑客攻擊&#xff0c;存在如下安全問題&#xff1a; 暴力破解密碼&#xff0c;造成用戶信息泄露短信盜刷的安全問題&#xff0c;影響業務及導致用戶投訴帶來經濟損失&#xff0c;尤其是后付費客戶&#xff0c;風險巨大&#xff0c;造成虧損無底洞…

dockerfile里的copy只能使用相對路徑嗎?

在 Dockerfile 中&#xff0c;COPY 指令既可以使用相對路徑&#xff0c;也可以使用絕對路徑&#xff08;但絕對路徑的使用方式和上下文有關&#xff09;。不過&#xff0c;在實踐中&#xff0c;你通常會看到使用相對路徑&#xff0c;因為 Dockerfile 的構建上下文&#xff08;b…

NewspaceGPT帶你玩系列之【Song Maker】

目錄 注冊一個賬號&#xff0c;用qq郵箱&#xff0c;然后登錄選一個可用的Plus&#xff0c;不要選3.5探索GPT今天的主角是【Song Maker】翻譯一下用漢語吧我寫詞。你譜曲和其他伴奏&#xff0c;例子&#xff1a; 搖滾&#xff0c;憂傷&#xff0c;吉他&#xff0c;鼓&#xff0…

聊一聊Oracle的空間計算函數SDO_NN

網上對這個函數介紹的很少&#xff0c;對使用上也很模糊&#xff0c;我來補充一下&#xff0c;讓大家了解一下這個函數 from test1 y, test2 p where SDO_NN(p.geom,y.geom,sdo_num_res1, 0.5 )TRUE; 上面這個表達式的含義也就是說在test2中找到一個距離test1很近的&#x…

Android約束布局的概念與屬性(1)

目錄 1&#xff0e;相對定位約束2&#xff0e;居中和偏移約束 約束布局&#xff08;ConstraintLayout&#xff09;是當前Android Studio默認的布局方式&#xff0c;也是最靈活的一種布局方式。約束布局推薦使用所見即所得的模式進行布局&#xff0c;約束布局的大部分布局可以通…

超詳細的 Linux 環境下 Anaconda 安裝與使用教程

超詳細的 Linux 環境下 Anaconda 安裝與使用教程 前言 在數據科學和機器學習領域&#xff0c;Anaconda 是一個非常受歡迎的發行版&#xff0c;提供了許多常用的包和工具。本文將詳細介紹如何在 Linux 系統上安裝和配置 Anaconda 環境&#xff0c;并展示如何高效地使用它。 一…

CentOS7下安裝Doris

Doris簡介 Apache Doris 是一款基于 MPP 架構的高性能、實時的分析型數據庫&#xff0c;以高效、簡單、統一的特點被人們所熟知&#xff0c;僅需亞秒級響應時間即可返回海量數據下的查詢結果&#xff0c;不僅可以支持高并發的點查詢場景&#xff0c;也能支持高吞吐的復雜分析場…

從0到1搭建個性化推送引擎:百數教學帶你掌握核心技術

百數低代碼的推送提醒功能允許用戶高度自定義提醒規則&#xff0c;支持多種提醒方式&#xff08;如釘釘、企業微信、微信、短信、語音、郵件等&#xff09;&#xff0c;以滿足不同場景下的需求。 通過預設字段和模板&#xff0c;用戶可以快速編輯提醒內容&#xff0c;減少重復…

BaseServlet的封裝

創建BaseServlet的必要性 如果不創建BaseServlet&#xff0c;現在我們只要實現一個功能&#xff0c;我們就需要創建一個servlet! 例如:用戶模塊(登錄&#xff0c;注冊&#xff0c;退出錄&#xff0c;激活&#xff0c;發送郵件等等功能) 也就是說&#xff0c;我們必須要創建一…

idea無法實力化id

解決&#xff1a;https://blog.csdn.net/qq_41264674/article/details/83409810?ops_request_misc&request_id&biz_id102&utm_termSerializable%E4%B8%8D%E8%87%AA%E5%8A%A8%E7%94%9F%E6%88%90%E5%AE%9E%E5%8A%9B%E5%8C%96id&utm_mediumdistribute.pc_search_…

java-數據結構與算法-02-數據結構-03-遞歸

1. 概述 定義 計算機科學中&#xff0c;遞歸是一種解決計算問題的方法&#xff0c;其中解決方案取決于同一類問題的更小子集 In computer science, recursion is a method of solving a computational problem where the solution depends on solutions to smaller instances…

IT項目經理轉行大模型,項目經理的進來,你想知道的都在這里非常詳細

大模型&#xff08;如人工智能、機器學習和深度學習模型&#xff09;可以通過提供數據驅動的決策支持、自動化流程和預測分析來賦能IT項目經理。這些工具可以幫助項目經理更有效地管理項目&#xff0c;預測潛在的風險&#xff0c;并提高項目成功的可能性。以下是IT項目經理如何…

IPD流程學習筆記

一、前言 互聯網行業講究的是快速試錯&#xff0c;所以IPD流程的應用并不多&#xff0c;但是傳統企業數字化轉型中&#xff0c;怎么確保項目投入可以切合市場需求&#xff0c;有較好的ROI及落地性&#xff0c;輕量級的IPD還是很有必要了解下的&#xff0c;特別是重資產類的業務…

探討大數據在視頻匯聚平臺LntonCVS國標GB28181協議中的應用

隨著攝像頭和視頻監控系統的普及和數字化程度的提高&#xff0c;視頻監控系統產生的數據量急劇增加。大數據技術因其優秀的數據管理、分析和利用能力&#xff0c;成為提升視頻監控系統效能和價值的重要工具。 大數據技術可以將視頻監控數據與其他數據源進行融合分析&#xff0c…

libaom 編碼器實驗 AV1 標準 SVC 分層編碼

SVC編碼 視頻SVC編碼&#xff0c;即Scalable Video Coding&#xff08;可適性視訊編碼或可分級視頻編碼&#xff09;&#xff0c;是H.264/MPEG-4 AVC編碼的一種擴展&#xff0c;它提供了更大的編碼彈性&#xff0c;并且具有時間可適性&#xff08;Temporal Scalability&#x…

單向鏈表的概念和結構

文章目錄 1.鏈表的概念及結構2.單鏈表的實現 1.鏈表的概念及結構 概念&#xff1a;鏈表是一種物理存儲結構上非連續、非順序的存儲結構&#xff0c;數據元素的邏輯順序是通過鏈表 中的指針鏈接次序實現的 。 鏈表的結構跟火車車廂相似&#xff0c;淡季時車次的車廂會相應減少&…

【基礎算法總結】分治—歸并

分治—歸并 1.排序數組2.交易逆序對的總數3.計算右側小于當前元素的個數4.翻轉對 點贊&#x1f44d;&#x1f44d;收藏&#x1f31f;&#x1f31f;關注&#x1f496;&#x1f496; 你的支持是對我最大的鼓勵&#xff0c;我們一起努力吧!&#x1f603;&#x1f603; 1.排序數組 …