jQuery实现查看图片功能


Posted in jQuery onDecember 01, 2020

本文实例为大家分享了jQuery实现查看图片的具体代码,供大家参考,具体内容如下

HTML

<!-- 放缩略图的div -->
  <div class="sl">
    <img src="images/1.jpg" />
    <img src="images/2.jpg" />
    <img src="images/3.jpg" />
  </div>
  <!-- 实现关灯的div -->
  <div class="gd"></div>
  <div class="yt">
    <!-- 左翻按钮 -->
    <div class="left">
      <img src="images/left.png" alt="" width="100">
    </div>
    <div class="tp">
      <!-- 展示原图 -->
      <img src="images/1.jpg" class="show" />
      <!--放开始和结束图片的盒子 -->
       <div class="ss" style="display: none;">
        <img src="images/start.png" alt="" width="50" class="start">
      </div>
    </div>
    <!-- 右翻按钮 -->
    <div class="right">
      <img src="images/right.png" alt="" width="100">
    </div>
</div>

CSS

html,body{
    padding: 0;
    margin: 0;
  }
  .sl img {
    width: 300px;
  }

  .gd {
    background-color: rgba(0, 0, 0, 0.7);
    position: absolute;
    z-index: 900;
    display: none;
    top: 0;
    left: 0;
  }

  .sl {
    position: absolute;
    z-index: 888;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
  }

  .sl>img {
    width: 25%;
  }

  .yt {
    z-index: 990;
    position: absolute;
    display: none;
    left: 500px;
    top: 200px;
  }

  .tp {
    margin: 0 20px;
  }

  .yt>div {
    display: inline-block;
  }

  .left,
  .right {
    position: relative;
    top: -110px;
    cursor: pointer;
  }

  .ss {
    position: relative;
    width: 50px;
    height: 50px;
    left: 270px;
  }

  .start {
    z-index: 990;
    position: absolute;
  }

JS

var max = $(".sl img").length;
$(function (e) {
  var width = $(window).width();
  var height = $(window).height();
  $(".gd").css({
    "height": height,
    "width": width
  });

  //左翻按钮动画
  $(".left").hover(
    function () {
      $(this).animate({
        "left": "-10"
      });
    },
    function () {
      $(this).animate({
        "left": "0"
      });
    }
  );
  //右翻按钮动画
  $(".right").hover(
    function () {
      $(this).animate({
        "right": "-10"
      });
    },
    function () {
      $(this).animate({
        "right": "0"
      });
    }
  );

  //被点击的缩略图
  $(".sl>img").click(function (e) {
    $(".gd").show(500);
    $(".yt").fadeIn(800);
    var index = $(this).index(); //当前被点击图片的索引
    $(".tp>img").attr("src", "images/" + (index + 1) + ".jpg");
    //左翻
    $(".left").click(function (e) {
      if (index - 1 < 0) {
        index = max - 1;
      } else {
        index = index - 1;
      }
      $(".tp>img").attr("src", "images/" + (index + 1) + ".jpg");
    });
    //右翻
    $(".right").click(function (e) {
      if (index == max - 1) {
        index = 0;
      } else {
        index = index + 1;
      }
      $(".tp>img").attr("src", "images/" + (index + 1) + ".jpg");
    });

    //隐藏和显示播放按钮
    $(".tp").hover(
      function () {
        $(".ss").fadeIn(500);
        $(this).animate({
          "opacity": "0.7"
        }, 700);
      },
      function () {
        $(".ss").fadeOut(500);
        $(this).animate({
          "opacity": "1"
        }, 700);
      }
    );
 //点击开始播放 再次点击结束播放
    let flag = true;
    $(".start").click(function () {
      if (flag == true) {
        time = setInterval(function () {
          if (index == max - 1) {
            index = 0;
          } else {
            index = index + 1;
          }
          $(".tp>img").attr("src", "images/" + (index + 1) + ".jpg");
        }, 2000);
        flag = false;
        $(".start").attr("src", "images/stop.png");
      } else {
        clearInterval(time);
        flag = true;
        $(".start").attr("src", "images/start.png");
      }
    });
    let h = $(".tp>img").height();
    $(".ss").css({
      "top": -h / 2 - 25
    });
    //隐藏关灯效果
    $(".gd").click(function () {
      $(".gd").hide(800);
      $(".yt").fadeOut(500);
    });
  });
});

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持三水点靠木。

jQuery 相关文章推荐
jQuery中map函数的两种方式
Apr 07 jQuery
jquery replace方法去空格
May 08 jQuery
jQuery实现的简单在线计算器功能
May 11 jQuery
jquery append与appendTo方法比较
May 24 jQuery
js案例之鼠标跟随jquery版(实例讲解)
Jul 21 jQuery
jQuery结合jQuery.cookie.js插件实现换肤功能示例
Oct 14 jQuery
jQuery实现的上传图片本地预览效果简单示例
Mar 29 jQuery
jQuery实现的响应鼠标移动方向插件用法示例【附源码下载】
Aug 28 jQuery
jQuery实现动态添加和删除input框实例代码
Mar 26 jQuery
基于jQuery实现挂号平台首页源码
Jan 06 jQuery
jquery插件实现轮播图效果
Oct 19 jQuery
详解jQuery的核心函数和事件处理
Feb 18 jQuery
基于jQuery拖拽事件的封装
Nov 29 #jQuery
jQuery实现动态操作table行
Nov 23 #jQuery
jQuery-App输入框实现实时搜索
Nov 19 #jQuery
JQuery+drag.js上传图片并且实现图片拖曳
Nov 18 #jQuery
JavaScript枚举选择jquery插件代码实例
Nov 17 #jQuery
如何在vue 中引入使用jquery
Nov 10 #jQuery
jquery实现加载更多&quot;转圈圈&quot;效果(示例代码)
Nov 09 #jQuery
You might like
php中计算时间差的几种方法
2009/12/31 PHP
深入PHP autoload机制的详解
2013/06/09 PHP
解析php中获取系统信息的方法
2013/06/25 PHP
php使用正则表达式提取字符串中尖括号、小括号、中括号、大括号中的字符串
2020/04/05 PHP
php数组排序usort、uksort与sort函数用法
2014/11/17 PHP
php静态文件返回304技巧分享
2015/01/06 PHP
隐性调用php程序的方法
2015/06/13 PHP
PHP微信API接口类
2016/08/22 PHP
PHP入门教程之面向对象基本概念实例分析
2016/09/11 PHP
PHP数组Key强制类型转换实现原理解析
2020/09/01 PHP
jquery获取下拉列表的值为null的解决方法
2011/03/18 Javascript
基于jquery的跟随屏幕滚动代码
2012/07/24 Javascript
Node.js(安装,启动,测试)
2014/06/09 Javascript
javascript实现youku的视频代码自适应宽度
2015/05/25 Javascript
灵活使用数组制作图片切换js实现
2016/07/28 Javascript
详解Nodejs基于mongoose模块的增删改查的操作
2016/12/21 NodeJs
Web前端框架Angular4.0.0 正式版发布
2017/03/28 Javascript
Node.js 8 中的重要新特性
2017/06/28 Javascript
ES6中的Promise代码详解
2017/10/09 Javascript
mint-ui 时间插件使用及获取选择值的方法
2018/02/09 Javascript
Vue.js的动态组件模板的实现
2018/11/26 Javascript
微信小程序返回箭头跳转到指定页面实例解析
2019/10/08 Javascript
[01:33]DOTA2上海特级锦标赛 LIQUID战队完整宣传片
2016/03/16 DOTA
Python中使用第三方库xlrd来写入Excel文件示例
2015/04/05 Python
Python中shutil模块的学习笔记教程
2017/04/04 Python
Python 经典面试题 21 道【不可错过】
2018/09/21 Python
Python 循环终止语句的三种方法小结
2019/06/24 Python
通过实例了解python__slots__使用方法
2020/09/14 Python
CSS3轻松实现圆角效果
2017/11/09 HTML / CSS
kmart凯马特官网:美国最大的打折零售商和全球最大的批发商之一
2016/11/17 全球购物
介绍一下你对SOA的认识
2016/04/24 面试题
法院实习人员自我鉴定
2013/09/26 职场文书
公积金转移接收函
2014/01/11 职场文书
初婚未育未抱养证明
2014/01/12 职场文书
2014年客服工作总结与计划
2014/12/09 职场文书
钱学森电影观后感
2015/06/04 职场文书