jQuery+css实现的切换图片功能代码


Posted in Javascript onJanuary 27, 2016

本文实例讲述了jQuery+css实现的切换图片功能代码。分享给大家供大家参考,具体如下:

运行效果截图如下:

jQuery+css实现的切换图片功能代码

具体代码如下:

<!DOCTYPE html>
<html> 
 <head>
  <title>demo</title>
  <script type="text/javascript" src="jquery.js"></script>
  <style type="text/css" >
   body {
    margin:0; padding:0;
   }
   .container {
    border:6px solid gray; background:black;
    width:600px; height:400px; position:relative;
    left:50%; margin-left:-300px; border-radius:6px;
    -webkit-border-radius:6px; -moz-border-radius:6px;
    overflow:hidden;
   }
   .text-center {
    text-align:center;
   }
   h1 {
     font-size:50px; color:gray; font-weight:bolder;
   }
   .imgUL {
    width:100%; height:100%; margin:0px; padding:0px; list-style:none;
   }
   .imgUL li {
    float:left; margin:0px; padding:0px; height:100%; 
    color:gray; font-weight:bolder; text-align:center;
    font-size:100px; line-height:400px;
   }
   .pageUL {
    position:relative; top:-40px; height:40px; list-style:none;
    margin:0px; padding:0px; float:right;
   }
   .pageUL li {
    float:left; display:block; width:36px;
    height:36px; border:2px solid red;
     margin-left:5px; border-radius:4px;
    -webkit-border-radius:4px; text-align:center;
    -moz-border-radius:4px; line-height:36px;
    color:gray; font-weight:bolder; cursor:pointer;
   }
   .pageUL li:hover {
    background:#5ACF00; color:black;
   }
   .pageUL li.active {
    background:#5ACF00; color:black;
   }
  </style>
  <script type="text/javascript" >
   $(document).ready(function(){
    var autoInterval = null,
     imgUL = $(".imgUL"),
     imgliList = imgUL.children("li"),
     liListLength = imgliList.length,
     pageUL = $('.pageUL'),
     pageLiList = pageUL.children('li'),
     pageLiListLength = pageLiList.length,
    // initialize
    activePageLi = $(pageLiList[0]);
    activePageLi.addClass('active');
    imgliList.width(600);
    imgUL.width(liListLength * 600);
    $(".pageUL li").mouseover(function(){
     mouseoverAnimate(this);
    }).mouseout(function(){
     createInterval();
    });
    createInterval();
    function mouseoverAnimate(_this){
     clearInterval(autoInterval);
     activePageLi.removeClass('active');
     activePageLi = $(_this);
     var pageNo = parseInt(activePageLi.html());
     activePageLi.addClass('active');
     imgUL.animate({
      'marginLeft': -600 * (pageNo - 1)
     }, 10);
    }
    function createInterval(){
     autoInterval = setInterval(function(){
      var pageNo = parseInt(activePageLi.html());
      pageNo++;
      if(pageNo > pageLiListLength) {
       pageNo = 1;
      }
      activePageLi.removeClass('active');
      activePageLi = $(pageLiList[pageNo - 1]);
      activePageLi.addClass('active');
      imgUL.animate({
       'marginLeft': -600*(pageNo - 1)
      }, 1100);
     }, 1500);
    }
   });
  </script>
 </head>
 <body>
  <h1 class="text-center">Demo</h1>
  <div class="container" id="container">
   <ul class="imgUL">
    <li>Page1</li>
    <li>Page2</li>
    <li>Page3</li>
    <li>Page4</li>
    <li>Page5</li>
    <li>Page6</li>
   </ul>
   <ul class="pageUL">
    <li>1</li>
    <li>2</li>
    <li>3</li>
    <li>4</li>
    <li>5</li>
    <li>6</li>
   </ul>
  </div>
 </body>
</html>

希望本文所述对大家jQuery程序设计有所帮助。

Javascript 相关文章推荐
10个基于jQuery或JavaScript的WYSIWYG 编辑器整理
May 06 Javascript
纯js实现背景图片切换效果代码
Nov 14 Javascript
js动态加载以及确定加载完成的代码
Jul 31 Javascript
javascript nextSibling 与 getNextElement(node) 使用介绍
Oct 13 Javascript
jquery写个checkbox——类似邮箱全选功能
Mar 19 Javascript
JS动态创建DOM元素的方法
Jun 09 Javascript
JavaScript之promise_动力节点Java学院整理
Jul 03 Javascript
Sublime Text新建.vue模板并高亮(图文教程)
Oct 26 Javascript
360doc网站不登录就无法复制内容的解决方法
Jan 27 Javascript
记一次webapck4 配置文件无效的解决历程
Sep 19 Javascript
微信小程序实现留言板(Storage)
Nov 02 Javascript
SpringBoot+Vue开发之Login校验规则、实现登录和重置事件
Oct 19 Javascript
javascript中的3种继承实现方法
Jan 27 #Javascript
jQuery+css实现的换页标签栏效果
Jan 27 #Javascript
js实现的彩色方块飞舞奇幻效果
Jan 27 #Javascript
JavaScript下的时间格式处理函数Date.prototype.format
Jan 27 #Javascript
基于JavaScript实现瀑布流效果(循环渐近)
Jan 27 #Javascript
jQuery Easyui学习之datagrid 动态添加、移除editor
Jan 27 #Javascript
js实现简单排列组合的方法
Jan 27 #Javascript
You might like
在PHP中使用Sockets 从Usenet中获取文件
2008/01/10 PHP
Zend Guard一些常见问题解答
2008/09/11 PHP
php 输出双引号&quot;与单引号'的方法
2010/05/09 PHP
WordPress中获取所使用的模板的页面ID的简单方法
2015/12/31 PHP
JavaScript中Object和Function的关系小结
2009/09/26 Javascript
简略的前端架构心得&amp;&amp;基于editor为例子的编码小技巧
2010/11/25 Javascript
javascript开发随笔二 动态加载js和文件
2011/11/25 Javascript
Javascript浮点数乘积运算出现多位小数的解决方法
2014/02/17 Javascript
js+cookies实现悬浮购物车的方法
2015/05/25 Javascript
详解nodejs 文本操作模块-fs模块(三)
2016/12/22 NodeJs
jQuery模拟实现天猫购物车动画效果实例代码
2017/05/25 jQuery
NodeJS爬虫实例之糗事百科
2017/12/14 NodeJs
vue脚手架及vue-router基本使用
2018/04/09 Javascript
Promise.all中对于reject的处理方法
2018/08/01 Javascript
实例分析Array.from(arr)与[...arr]到底有何不同
2019/04/09 Javascript
JS前端知识点 运算符优先级,URL编码与解码,String,Math,arguments操作整理总结
2019/06/27 Javascript
[00:27]DOTA2荣耀之路2:Patience from zhou!
2018/05/24 DOTA
使用python实现拉钩网上的FizzBuzzWhizz问题示例
2014/05/05 Python
Python如何实现文本转语音
2016/08/08 Python
python解决汉字编码问题:Unicode Decode Error
2017/01/19 Python
django站点管理详解
2017/12/12 Python
Python搭建FTP服务器的方法示例
2018/01/19 Python
python判断列表的连续数字范围并分块的方法
2018/11/16 Python
解决Python3 被PHP程序调用执行返回乱码的问题
2019/02/16 Python
Python中按键来获取指定的值
2019/03/02 Python
Python 私有化操作实例分析
2019/11/21 Python
Python 识别12306图片验证码物品的实现示例
2020/01/20 Python
python怎么删除缓存文件
2020/07/19 Python
css3使网页、图片变成灰色兼容大多数浏览器
2014/07/02 HTML / CSS
产假请假条
2014/04/10 职场文书
医德医风演讲稿
2014/05/20 职场文书
医院科室评语
2015/01/04 职场文书
小学班主任研修日志
2015/11/13 职场文书
新店开业策划方案怎么书写?
2019/07/05 职场文书
Python函数式编程中itertools模块详解
2021/09/15 Python
Oracle 11g数据库使用expdp每周进行数据备份并上传到备份服务器
2022/06/28 Oracle