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 相关文章推荐
如何取得中文输入的真实长度?
Jun 24 Javascript
2007/12/23更新创意无限,简单实用(javascript log)
Dec 24 Javascript
js随机颜色代码的多种实现方式
Apr 23 Javascript
JS实现带有3D立体感的银灰色竖排折叠菜单代码
Oct 20 Javascript
基于jQuery的AJAX和JSON实现纯html数据模板
Aug 09 Javascript
connection reset by peer问题总结及解决方案
Oct 21 Javascript
AngularJS中如何使用echart插件示例详解
Oct 26 Javascript
如何利用JQuery实现从底部回到顶部的功能
Dec 27 Javascript
jquery 手势密码插件
Mar 17 Javascript
js获取浏览器的各种属性
Apr 27 Javascript
layer子层给父层页面元素赋值,以达到向父层页面传值的效果实例
Sep 22 Javascript
vue中$nextTick的用法讲解
Jan 17 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 检查扩展库或函数是否可用的代码
2010/04/06 PHP
YII2框架中使用yii.js实现的post请求
2017/04/09 PHP
PHP中phar包的使用教程
2017/06/14 PHP
尽可能写&quot;友好&quot;的&quot;Javascript&quot;代码
2007/01/09 Javascript
javascript同步Import,同步调用外部js的方法
2008/07/08 Javascript
csdn 博客的css样式 v3
2009/02/24 Javascript
innerText和innerHTML 一些问题分析
2009/05/18 Javascript
CSS+Jquery实现页面圆角框方法大全
2009/12/24 Javascript
Textbox控件注册回车事件及触发按钮提交事件具体实现
2013/03/04 Javascript
用jquery中插件dialog实现弹框效果实例代码
2013/11/15 Javascript
浅析JQuery UI Dialog的样式设置问题
2013/12/18 Javascript
jQery使网页在显示器上居中显示适用于任何分辨率
2014/06/09 Javascript
jQuery中nextAll()方法用法实例
2015/01/07 Javascript
js获取域名的方法
2015/01/27 Javascript
全面解析Bootstrap表单使用方法(表单按钮)
2015/11/24 Javascript
jquery动态遍历Json对象的属性和值的方法
2016/07/27 Javascript
jQuery自定义多选下拉框效果
2017/06/19 jQuery
在Vue项目中使用d3.js的实例代码
2018/05/01 Javascript
layui框架table 数据表格的方法级渲染详解
2018/08/19 Javascript
vue router 源码概览案例分析
2018/10/09 Javascript
浅谈Vue static 静态资源路径 和 style问题
2020/11/07 Javascript
python 图片验证码代码分享
2012/07/04 Python
Python实现PS滤镜Fish lens图像扭曲效果示例
2018/01/29 Python
Python中实现单例模式的n种方式和原理
2018/11/14 Python
python基于递归解决背包问题详解
2019/07/03 Python
Pytorch加载部分预训练模型的参数实例
2019/08/18 Python
简单易懂Pytorch实战实例VGG深度网络
2019/08/27 Python
python matplotlib绘制三维图的示例
2020/09/24 Python
SOA面试题:如何在SOA中实现松耦合
2013/07/21 面试题
调解协议书
2014/04/16 职场文书
2014年社会实践活动总结范文
2014/04/29 职场文书
教师“一帮一”结对子活动总结
2015/05/07 职场文书
悬崖上的金鱼姬观后感
2015/06/15 职场文书
导游词之台湾安平古堡
2019/12/25 职场文书
MySQL创建表操作命令分享
2022/03/25 MySQL
MySql数据库触发器使用教程
2022/06/01 MySQL