JQuery和html+css实现带小圆点和左右按钮的轮播图实例


Posted in jQuery onJuly 22, 2017

是的!你没看错!还是轮播图。这次的JQuery的哟!!

CSS代码:

/*轮播图 左右按钮 小白点*/
  #second_div{
  margin-top: 160px;
  }
  .img_box{
  overflow: hidden;
  width:100%;
  height:420px;
  border:1px solid;
  position:relative;
 }  
  .img_box img{
  width:100%;
  position:absolute;
 }  
  .ul5{
  list-style: none;
  position:absolute;
  left:580px;
  top:565px;
  } 
  .ul5 li{
  float:left;
  margin-left:20px;
  width:40px;
  height:5px;
  border:0px;
  background:lawngreen;
 }
  .d1,.d2{
  width:50px;
  height:60px;
  background-color: rgba(10,10,10,0.5);
  text-align: center;
  font-size:26px;
  font-weight: 800px;
  line-height:60px;
  cursor: pointer;
  }
  .d1{
  position:absolute;
  top:373px;
  left:25px;
  }
  .d2{
  position:absolute;
  top:373px;
  left:1445px;
  }

HTML代码:

<!-- 轮播图 -->
<div id="second_div">
<div class="img_box">
 <img src="img/ban1.jpg">
 <img src="img/ban2.jpg">
 <img src="img/ban3.jpg">
 <img src="img/ban4.png">
</div> 
 <ul class="ul5">
 <li></li>
 <li></li>
 <li></li>
 <li></li>
</ul>
 <div class="d1"><</div>
 <div class="d2">></div>
</div>

js代码:

<script type="text/javascript">
  $(document).ready(function(){
//搜索按钮
 $("#ss").click(function(){
  var new_li = $("<li>"+ $("#skuang").val() +"</li>");
  $("#d1 ul").append(new_li);
  $("#d1").hide();
  $("#skuang").val("");

  })

  $("#skuang").focus(function(){
   $("#d1").css("display","block");
  });
  
  $("#skuang").blur();
  $("#qingch").click(function(){
   $("#d1 li:gt(0)").remove();
   $("#d1").hide();
   
  });

//轮播图
  var img=$(".img_box img");
  var li=$(".ul5 li");
  var divW=$(".img_box").width();
  var len=$(".img_box img").length;
  img.css("left",divW);
  img.eq(0).css("left",0);
  li.eq(0).css("background","red");
  var index=0;
  var next=0;
  function show(){
   next++;
   if(next==len){
    next=0;
   }
   img.eq(next).css("left",divW);
   img.eq(index).animate({"left":-divW});
   img.eq(next).animate({"left":0});
   li.eq(next).css("background","red");
   li.eq(index).css("background","lawngreen");
   index=next;
  }
  t=setInterval(show,2000);
  function show1(){
   next--;
   if(next==-1){
    next=len-1;
   }
   img.eq(next).css("left",-divW);
   img.eq(index).animate({"left":divW});
   img.eq(next).animate({"left":0});
   li.eq(next).css("background","red");
   li.eq(index).css("background","lawngreen");
   index=next;     
  }
  img.hover(function(){
   clearInterval(t);     
  },function(){
   t=setInterval(show,2000);
  })
  //左右按钮
  $(".d2").mousedown(function(){
   clearInterval(t);
   show();
  })
  $(".d2").mousedown(function(){
     t=setInterval(show,2000);
  }) 
  $(".d1").mousedown(function(){
   clearInterval(t);
     show1();
  })
  $(".d1").mousedown(function(){
   t=setInterval(show,2000);
  })
  //小白点 点击
  li.mousedown(function(){
   num=$(this).index();
   if(num==next){
    return;
   }else if(num<next){
    clearInterval(t);
    img.eq(num).css("left",-divW);
     img.eq(index).animate({"left":divW});
     img.eq(num).animate({"left":0});
     li.eq(num).css("background","red");
     li.eq(index).css("background","lawngreen");
     index=num;
     next=num;
   }else if(num>next){
    clearInterval(t);
     img.eq(num).css("left",divW);
     img.eq(index).animate({"left":-divW});
     img.eq(num).animate({"left":0});
     li.eq(num).css("background","red");
     li.eq(index).css("background","lawngreen");
     index=num;
     next=num;
   }
 })
    li.mouseup(function(){
     t=setInterval(show,2000);
   })
  })
 </script>

以上这篇JQuery和html+css实现带小圆点和左右按钮的轮播图实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持三水点靠木。

jQuery 相关文章推荐
jquery平滑滚动到顶部插件使用详解
May 08 jQuery
jQuery实现radio第一次点击选中第二次点击取消功能
May 15 jQuery
JQuery.dataTables表格插件添加跳转到指定页
Jun 09 jQuery
jquery与js实现全选功能的区别
Jun 11 jQuery
jQuery实现 RadioButton做必选校验功能
Jun 15 jQuery
jQuery Validate插件ajax方式验证输入值的实例
Dec 21 jQuery
jQuery实现表格的增、删、改操作示例
Jan 27 jQuery
jQuery动态生成的元素绑定事件操作实例分析
May 04 jQuery
jQuery实现动态生成年月日级联下拉列表示例
May 11 jQuery
如何使用CSS3和JQuery easing 插件制作绚丽菜单
Jun 18 jQuery
jQuery HTML获取内容和属性操作实例分析
May 20 jQuery
jquery实现拖拽小方块效果
Dec 10 jQuery
js案例之鼠标跟随jquery版(实例讲解)
Jul 21 #jQuery
基于jQuery实现手风琴菜单、层级菜单、置顶菜单、无缝滚动效果
Jul 20 #jQuery
jQuery实现可编辑表格并生成json结果(实例代码)
Jul 19 #jQuery
jQuery实现导航栏头部菜单项点击后变换颜色的方法
Jul 19 #jQuery
利用jQuery异步上传文件的插件用法详解
Jul 19 #jQuery
jQuery Validate格式验证功能实例代码(包括重名验证)
Jul 18 #jQuery
jquery版轮播图效果和extend扩展
Jul 18 #jQuery
You might like
写php分页时出现的Fatal error的解决方法
2011/04/18 PHP
php学习之简单计算器实现代码
2011/06/09 PHP
php实现用户在线时间统计详解
2011/10/08 PHP
php打开远程文件的方法和风险及解决方法
2013/11/12 PHP
php生成与读取excel文件
2016/10/14 PHP
贴一个在Mozilla中常用的Javascript代码
2007/01/09 Javascript
JQuery中节点遍历方法实例
2015/05/18 Javascript
解决jquery无法找到其他父级子集问题的方法
2016/05/10 Javascript
省市联动效果的简单实现代码(推荐)
2016/06/06 Javascript
H5移动端适配 Flexible方案
2016/10/24 Javascript
React 组件渲染和更新的实现代码示例
2019/02/21 Javascript
详解VUE Element-UI多级菜单动态渲染的组件
2019/04/25 Javascript
element-ui中Table表格省市区合并单元格的方法实现
2019/08/07 Javascript
jsonp格式前端发送和后台接受写法的代码详解
2019/11/07 Javascript
[01:35]辉夜杯战队访谈宣传片—iG.V
2015/12/25 DOTA
Python基于Matplotlib库简单绘制折线图的方法示例
2017/08/14 Python
python安装模块如何通过setup.py安装(超简单)
2018/05/05 Python
Python简易版图书管理系统
2019/08/12 Python
Python 私有化操作实例分析
2019/11/21 Python
python3.7通过thrift操作hbase的示例代码
2020/01/14 Python
Python中itertools的用法详解
2020/02/07 Python
IntelliJ 中配置 Anaconda的过程图解
2020/06/01 Python
浅谈keras使用中val_acc和acc值不同步的思考
2020/06/18 Python
CSS3线性渐变简单实现以及该属性在浏览器中的不同
2012/12/12 HTML / CSS
DKNY品牌官网:纽约大都会时尚风格
2016/10/20 全球购物
英国定做窗帘和纺织品面料一站式商店:Dekoria
2018/08/29 全球购物
iostream与iostream.h的区别
2015/01/16 面试题
承认错误的检讨书
2014/01/30 职场文书
医院学雷锋活动策划方案
2014/02/15 职场文书
会计学专业自荐信
2014/06/25 职场文书
党员干部民主生活会议批评与自我批评材料
2014/09/20 职场文书
故意伤害辩护词
2015/05/21 职场文书
会计入职心得体会
2016/01/22 职场文书
Python基于百度API识别并提取图片中文字
2021/06/27 Python
python数字转对应中文的方法总结
2021/08/02 Python
配置Kubernetes外网访问集群
2022/03/31 Servers