淘宝轮播图带前后按钮

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style>
*{margin:0 ;padding:0;}
#div1{width:520px; height:280px; position:relative; overflow:hidden;  margin:50px auto;}
#ul1{position:absolute; left:0; top:0; }
#ul1 li{float:left; list-style:none; width:520px; height:280px;}
#span1{z-index:3;position:absolute; text-align:center;}
#span1 span{display:block; width:20px; height:20px;background:blue; color:white; margin:6px;}
</style>
</head>

<body>
<div id="div1">
  <ul id="ul1">
    <li><img src="1.jpg" /></li> 
    <li><img src="2.jpg" /></li> 
    <li><img src="3.jpg" /></li> 
    <li><img src="4.jpg" /></li> 
   </ul>
   <div id="span1">
   <span>1</span>
   <span>2</span>
   <span>3</span>
   <span>4</span>
   </div>
</div>
<span  id="prev">上张</span>
<span  id="next">下账</span>
<script>
window.onload=function(){
    var oPrev=document.getElementById('prev');
    var oNext=document.getElementById('next');
    var oUl=document.getElementById('ul1');
    var oDiv=document.getElementById('div1');
    var oSpanBox=document.getElementById('span1');
    var oSpan=oSpanBox.getElementsByTagName('span');
    var oLi=oUl.getElementsByTagName('li');
    var oP=true;
    oUl.style.width=oLi[0].offsetWidth*oLi.length+'px';
    function al(){oP=!oP}
    for(var i=0; i<oLi.length;i++){
        oSpan[i].index=i;
        oSpan[i].onclick=function(){
          startMove(oUl,{'left':oLi[0].offsetWidth*this.index*-1})
        }
    }
    oPrev.onclick=function(){
        if(oUl.offsetLeft<0 && oP){
            oP=!oP;     //开关,防止连续点击错误
            startMove(oUl,{'left':oUl.offsetLeft+oLi[0].offsetWidth},al);
        }else{
           return false;    
        }
        
    }
    oNext.onclick=function(){
        if(oUl.offsetLeft>-oLi[0].offsetWidth*(oLi.length)&&oP){
            oP=!oP;
            startMove(oUl,{'left':oUl.offsetLeft-oLi[0].offsetWidth},al)
        }else{
           return false;    
        }
        
    }
}
</script>
<script src="move.js"></script>
</body>
</html>

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个简单的淘宝轮播图的HTML代码示例: ```html <!DOCTYPE html> <html> <head> <title>淘宝轮播图</title> <style> .carousel { position: relative; width: 600px; height: 400px; overflow: hidden; } .carousel img { width: 100%; height: 100%; } .carousel .prev, .carousel .next { position: absolute; top: 50%; transform: translateY(-50%); width: 50px; height: 50px; background-color: rgba(0, 0, 0, 0.5); color: #fff; text-align: center; line-height: 50px; cursor: pointer; } .carousel .prev { left: 10px; } .carousel .next { right: 10px; } .carousel .dots { position: absolute; bottom: 10px; left: 50%; transform: translateX(-50%); display: flex; } .carousel .dot { width: 10px; height: 10px; background-color: #ccc; border-radius: 50%; margin: 0 5px; cursor: pointer; } .carousel .dot.active { background-color: #333; } </style> </head> <body> <div class="carousel"> <img src="image1.jpg" alt="Image 1"> <img src="image2.jpg" alt="Image 2"> <img src="image3.jpg" alt="Image 3"> <div class="prev">‹</div> <div class="next">›</div> <div class="dots"> <div class="dot"></div> <div class="dot"></div> <div class="dot"></div> </div> </div> <script> var carousel = document.querySelector('.carousel'); var prevButton = carousel.querySelector('.prev'); var nextButton = carousel.querySelector('.next'); var dots = carousel.querySelectorAll('.dot'); var images = carousel.querySelectorAll('img'); var currentIndex = 0; function showImage(index) { for (var i = 0; i < images.length; i++) { images[i].style.display = 'none'; dots[i].classList.remove('active'); } images[index].style.display = 'block'; dots[index].classList.add('active'); } function prevImage() { currentIndex--; if (currentIndex < 0) { currentIndex = images.length - 1; } showImage(currentIndex); } function nextImage() { currentIndex++; if (currentIndex >= images.length) { currentIndex = 0; } showImage(currentIndex); } prevButton.addEventListener('click', prevImage); nextButton.addEventListener('click', nextImage); for (var i = 0; i < dots.length; i++) { dots[i].addEventListener('click', function() { var dotIndex = Array.prototype.indexOf.call(dots, this); showImage(dotIndex); }); } showImage(currentIndex); </script> </body> </html> ``` 这段代码实现了一个基本的淘宝轮播图效果,包括左右箭头切换图片和底部的小圆点指示器。你可以根据需要修改图片地址和样式来适应你的项目。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值