nbsp;html> <htmllang> <metacharset> <metaname> <title>Document</title> <linkrel> <style> html,body{ width:100%; overflow-x:hidden; } html{ font-size:100px; } .banner{ position:relative; height:3rem; overflow:hidden; } .banner .wrapper{ position:absolute; top:0; left:-100%; height:100%; } .banner .wrapper .slide{ float:left; height:100%; background:#eee; } .banner .wrapper .slide img{ display:none; width:100%; height:100%; } .tip{ position:absolute; left:0; bottom:.1rem; width:100%; height:.16rem; text-align:center; } .tip li{ display:inline-block; margin:0 .03rem; width:.16rem; height:.16rem; background:rgba(0,0,0,0.2); border-radius:50%; vertical-align:top; } .tip li.bg{ background:#007aff; } </style> <sectionclass> <pclass> <!--实现无缝滚动:把第一张放末尾 最后一张放开头--> <pclass><img src="/static/imghwm/default1.png" data-src="img/banner5.jpg" class="lazy" alt=""> <pclass><img src="/static/imghwm/default1.png" data-src="img/banner1.jpg" class="lazy" alt=""> <pclass><img src="/static/imghwm/default1.png" data-src="img/banner2.jpg" class="lazy" alt=""> <pclass><img src="/static/imghwm/default1.png" data-src="img/banner3.jpg" class="lazy" alt=""> <pclass><img src="/static/imghwm/default1.png" data-src="img/banner4.jpg" class="lazy" alt=""> <pclass><img src="/static/imghwm/default1.png" data-src="img/banner5.jpg" class="lazy" alt=""> <pclass><img src="/static/imghwm/default1.png" data-src="img/banner1.jpg" class="lazy" alt=""> <ulclass> <liclass> <li> <li> <li> <li> <scriptcharset> <scriptcharset> //REM ~function(){ document.documentElement.style.fontSize = document.documentElement.clientWidth/640*100 + 'px'; }() //页面中如果自己使用了TOUCH MOVE等原生事件,需要把浏览器的默认行为阻止掉 $(document).on('touchmove touchstart touchend',function(ev){ ev.preventDefault(); }) //BANNER var bannerRender = (function(){ var winW = document.documentElement.clientWidth, maxL = 0, minL = 0; var $banner = $('.banner'), $wrapper = $banner.children('.wrapper'), $slideList = $wrapper.children('.slide'), $imgList = $wrapper.find('img'); var step = 1, count = 0, followTimer = null; //public fn function isSwipe(strX,strY,endX,endY){ return Math.abs(endX - strX)>30 || Math.abs(endY - strY) > 30) } function swipeDir(strX,strY,endX,endY){ return Math.abs(endX - strX)>=Math.abs(endY - strY)?(endX - strX>0?'right':'left'):(endY - strY>0?'down':'up'); } //touch start function dragStart(ev){ var point = ev.touches[0]; $wrapper.attr({ strL:parseFloat($wrapper.css('left')), strX:point.clientX, strY:point.clientY, isMove:false, dir:null, changeX:null }) } //touch move function dragIng(ev){ var point = ev.touches[0]; var endX = point.clientX, endY = point.clientY, strX = parseFloat($wrapper.attr('strX')), strY = parseFloat($wrapper.attr('strY')), strL = parseFloat($wrapper.attr('strL')), changeX = endX - strX; //计算出是否滑动以及滑动的方向:只有是左右滑动才进行处理 var isMove = isSwipe(strX,strY,endX,endY), dir = swipeDir(strX,strY,endX,endY); if(isMove && /(left|right)/i.test(dir)){ $wrapper.attr({ isMove:true, dir:dir, changeX:changeX }); var curL = strL+changeX; curL = curL>maxL?maxL:(curL<minl>=winW/2){ if(dir==='left'){ step++; }else{ step--; } } } $wrapper[0].style.webkitTransitionDuration = '.2s'; $wrapper.css('left',-step*winW); lazyImg(); //动画运动过程中,我们监听一个定时器:动画运动完成判断当前是否运动到边界,如果运动到达了边界,我们让其立马回到自己的真实位置 window.clearTimeout(followTimer) followTimer = window.setTimeout(function(){ if(step===0){ $wrapper[0].style.webkitTransitionDuration = '0s'; $wrapper.css('left',-(count-2)*winW); step = count-2; lazyImg(); } if(step===count-1){ $wrapper[0].style.webkitTransitionDuration = '0s'; $wrapper.css('left',-winW); step = 1; lazyImg(); } window.clearTimeout(followTimer) },200) } //图片延迟加载,让当前的活动块及相邻的两个活动块进行加载 function lazyImg(){ var $cur = $slideList.eq(step), $tar = $cur.add($cur.prev()).add($cur.next()); $tar.each(function(index,item){ var $img = $(item).children('img'); if($img.attr('isLoad')==='true'){ //ATTR存储或者获取的属性值都是一个字符串,如果当前的图片已经加载过了,我们就不需要重新的加载了 return; } var oImg = new Image; oImg.src = $img.attr('src'); oImg.onload = function(){ $img.attr({ src:this.src, isLoad:true }).css('display','block') oImg = null; } }) } return{ init:function(){ //init css style count = $slideList.length; minL = -($slideList.length-1)*winW; $wrapper.css('width',$slideList.length*winW); $slideList.css('width',winW); //lazy img lazyImg(); $banner.on('touchstart',dragStart).on('touchmove',dragIng).on('touchend',dragEnd) } } })() bannerRender.init(); </minl></scriptcharset></scriptcharset></liclass></ulclass></pclass></pclass></pclass></pclass></pclass></pclass></pclass></pclass></sectionclass></linkrel></metaname></metacharset></htmllang>
以上是js實作在行動裝置圖片輪播的詳細內容。更多資訊請關注PHP中文網其他相關文章!

Node.js擅長於高效I/O,這在很大程度上要歸功於流。 流媒體匯總處理數據,避免內存過載 - 大型文件,網絡任務和實時應用程序的理想。將流與打字稿的類型安全結合起來創建POWE

Python和JavaScript在性能和效率方面的差異主要體現在:1)Python作為解釋型語言,運行速度較慢,但開發效率高,適合快速原型開發;2)JavaScript在瀏覽器中受限於單線程,但在Node.js中可利用多線程和異步I/O提升性能,兩者在實際項目中各有優勢。

JavaScript起源於1995年,由布蘭登·艾克創造,實現語言為C語言。 1.C語言為JavaScript提供了高性能和系統級編程能力。 2.JavaScript的內存管理和性能優化依賴於C語言。 3.C語言的跨平台特性幫助JavaScript在不同操作系統上高效運行。

JavaScript在瀏覽器和Node.js環境中運行,依賴JavaScript引擎解析和執行代碼。 1)解析階段生成抽象語法樹(AST);2)編譯階段將AST轉換為字節碼或機器碼;3)執行階段執行編譯後的代碼。

Python和JavaScript的未來趨勢包括:1.Python將鞏固在科學計算和AI領域的地位,2.JavaScript將推動Web技術發展,3.跨平台開發將成為熱門,4.性能優化將是重點。兩者都將繼續在各自領域擴展應用場景,並在性能上有更多突破。

Python和JavaScript在開發環境上的選擇都很重要。 1)Python的開發環境包括PyCharm、JupyterNotebook和Anaconda,適合數據科學和快速原型開發。 2)JavaScript的開發環境包括Node.js、VSCode和Webpack,適用於前端和後端開發。根據項目需求選擇合適的工具可以提高開發效率和項目成功率。

是的,JavaScript的引擎核心是用C語言編寫的。 1)C語言提供了高效性能和底層控制,適合JavaScript引擎的開發。 2)以V8引擎為例,其核心用C 編寫,結合了C的效率和麵向對象特性。 3)JavaScript引擎的工作原理包括解析、編譯和執行,C語言在這些過程中發揮關鍵作用。

JavaScript是現代網站的核心,因為它增強了網頁的交互性和動態性。 1)它允許在不刷新頁面的情況下改變內容,2)通過DOMAPI操作網頁,3)支持複雜的交互效果如動畫和拖放,4)優化性能和最佳實踐提高用戶體驗。


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

DVWA
Damn Vulnerable Web App (DVWA) 是一個PHP/MySQL的Web應用程序,非常容易受到攻擊。它的主要目標是成為安全專業人員在合法環境中測試自己的技能和工具的輔助工具,幫助Web開發人員更好地理解保護網路應用程式的過程,並幫助教師/學生在課堂環境中教授/學習Web應用程式安全性。 DVWA的目標是透過簡單直接的介面練習一些最常見的Web漏洞,難度各不相同。請注意,該軟體中

禪工作室 13.0.1
強大的PHP整合開發環境

MantisBT
Mantis是一個易於部署的基於Web的缺陷追蹤工具,用於幫助產品缺陷追蹤。它需要PHP、MySQL和一個Web伺服器。請查看我們的演示和託管服務。

ZendStudio 13.5.1 Mac
強大的PHP整合開發環境