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监听扫码枪输入并禁止手动输入的实现方法(推荐)
Mar 21 jQuery
关于jQuery库冲突的完美解决办法
May 20 jQuery
jQuery实现简单的滑动导航代码(移动端)
May 22 jQuery
jQuery异步提交表单实例
May 30 jQuery
jQuery中ajax获取数据赋值给页面的实例
Dec 31 jQuery
jQuery中each方法的使用详解
Mar 18 jQuery
JS文件中加载jquery.js的实例代码
May 05 jQuery
jquery登录的异步验证操作示例
May 09 jQuery
jQuery实现文本显示一段时间后隐藏的方法分析
Jun 20 jQuery
jQuery HTML css()方法与css类实例详解
May 20 jQuery
Jquery滑动门/tab切换实现方法完整示例
Jun 05 jQuery
基于ajax及jQuery实现局部刷新过程解析
Sep 12 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的优点与缺点
2013/04/11 PHP
thinkphp 多表 事务详解
2013/06/17 PHP
PHP使用PHPExcel删除Excel单元格指定列的方法
2016/07/06 PHP
qTip 基于JQuery的Tooltip插件[兼容性好]
2010/09/01 Javascript
javascript history对象(历史记录)使用方法(实现浏览器前进后退)
2014/01/07 Javascript
JavaScript获取图片像素颜色并转换为box-shadow显示
2016/03/11 Javascript
用js动态添加html元素,以及属性的简单实例
2016/07/19 Javascript
jquery中用jsonp实现搜索框功能
2016/10/18 Javascript
详解基于node的前端项目编译时内存溢出问题
2017/08/01 Javascript
js实现数组内数据的上移和下移的实例
2017/11/14 Javascript
Node.js中sequelize时区的配置方法
2017/12/10 Javascript
详解webpack提取第三方库的正确姿势
2017/12/22 Javascript
vue项目页面嵌入代码块vue-prism-editor的实现
2020/10/30 Javascript
跟老齐学Python之开始真正编程
2014/09/12 Python
Python中的Matplotlib模块入门教程
2015/04/15 Python
深入解析Python中的上下文管理器
2016/06/28 Python
Python的Flask框架中的Jinja2模板引擎学习教程
2016/06/30 Python
python开发环境PyScripter中文乱码问题解决方案
2016/09/11 Python
python实现猜拳小游戏
2020/04/05 Python
使用Python进行中文繁简转换的实现代码
2019/10/18 Python
matplotlib.pyplot画图并导出保存的实例
2019/12/07 Python
python自动脚本的pyautogui入门学习
2020/04/01 Python
css实例教程 一款纯css3实现的超炫动画背画特效
2014/11/05 HTML / CSS
从一次项目重构说起CSS3自定义变量在项目的使用方法
2021/03/01 HTML / CSS
酒吧员工的岗位职责
2013/11/26 职场文书
大学生写自荐信的技巧
2014/01/08 职场文书
新文化运动的基本口号
2014/06/21 职场文书
动画设计系毕业生求职信
2014/07/15 职场文书
五一劳动节演讲稿
2014/09/12 职场文书
党员批评与自我批评发言稿
2014/10/14 职场文书
银行资信证明
2015/06/17 职场文书
公司员工宿舍管理制度
2015/08/07 职场文书
Python编写可视化界面的全过程(Python+PyCharm+PyQt)
2021/05/17 Python
Go语言设计模式之结构型模式
2021/06/22 Golang
关于Python中*args和**kwargs的深入理解
2021/08/07 Python
Mysql排查分析慢sql之explain实战案例
2022/04/19 MySQL