簡單的左右滾動輪播圖
阿新 • • 發佈:2017-09-09
nsf javascrip pan position 個數 webkit translate over gin
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <style> .slide { width: 100%; height: 100%; } .slider{ width: 100%; height: 100%; position: relative; cursor: all-scroll; display: flex; left: -100%; } .trans-select{ -webkit-transform: translate3d(0, 0, 0); transform: translate3d(0, 0, 0); will-change: transform; -webkit-user-select: none; -moz-user-select: none;-ms-user-select: none; user-select: none; } .con{ width: 100%; height: 127px; padding: 0;margin: 0; overflow: hidden; /*做全屏滾動banner的關鍵*/ } </style> </head> <body> <div class="con"> <div class="slider trans-select"> <img class="slide sw" src="images/b1.jpg" > <img class="slide sw" src="images/b2.jpg" > </div> </div> <script type="text/javascript" src="js/jquery-1.11.3.js"></script> <script> var$slider = $(‘.slider‘); //在第一屏前添加輔助圖,消除移動時的空白間隙 var cloneNode=$(‘.slide:last‘).clone().removeClass(‘sw‘); $slider.children(‘.slide.sw‘).first().before(cloneNode); var numOfBanner=$slider.find(‘.slide‘).length; // 輪播圖個數 $slider.css({‘width‘:100*numOfBanner+‘vw‘ }); var slideLeft=function(target){ $slider.animate({ ‘left‘: ‘-200%‘ }, ‘750‘, function(){ $slider.css({‘left‘: ‘-100%‘}); // for(var i=0;i<Math.abs(target);i++){ $slider.children(‘.slide.sw‘).first().before( $slider.children(‘.slide.sw‘).last() ); // } } ); }; setInterval(slideLeft,2000); </script> </body> </html>
簡單的左右滾動輪播圖