淘宝轮播图带前后按钮

简介: DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.
<!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>

 

相关文章
|
7天前
|
前端开发 JavaScript 容器
实现一个移动端焦点轮播图
实现一个移动端焦点轮播图
|
7月前
|
前端开发 JavaScript
HTML+CSS+JS仿京东购物车页面动态效果
HTML+CSS+JS仿京东购物车页面动态效果
93 0
|
4月前
|
前端开发
HTML+CSS实现轮播图效果
HTML+CSS实现轮播图效果
|
5月前
|
小程序 JavaScript
微信小程序商品筛选,侧方弹出动画选择页面
微信小程序商品筛选,侧方弹出动画选择页面
140 0
|
10月前
一个小轮播图
一个小轮播图
49 0
|
小程序
【微信小程序】滚动 轮播图 文本
🍒小程序的宿主环境 - 组件 1.scroll-view 组件的基本使用 2.swiper 和 swiper-item 组件的基本使用 3.text 组件的基本使用 4.rich-text 组件的基本使用
【微信小程序】滚动 轮播图 文本
|
11月前
|
小程序 开发者
微信小程序+轮播图+弹窗等设置
微信小程序+轮播图+弹窗等设置
121 0
|
11月前
|
小程序 JavaScript
微信小程序图片放大预览效果的实现,轮播图点击放大预览
微信小程序图片放大预览效果的实现,轮播图点击放大预览
832 0
|
11月前
|
JavaScript Serverless 容器
ue仿携程轮播图效果(滑动轮播,下方高度自适应)
这篇文章主要介绍了vue仿携程轮播图效果(滑动轮播,下方高度自适应),本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下