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插件HighCharts绘制2D饼图效果示例【附demo源码下载】
Mar 21 jQuery
jquery实现全选、全不选以及单选功能
Mar 23 jQuery
jQuery+PHP+Mysql实现抽奖程序
Apr 12 jQuery
使用 jQuery 实现表单验证功能
Jul 05 jQuery
利用jQuery异步上传文件的插件用法详解
Jul 19 jQuery
jQuery Layer弹出层传值到父页面的实现代码
Aug 17 jQuery
使用jQuery实现页面定时弹出广告效果
Aug 24 jQuery
jQuery md5加密插件jQuery.md5.js用法示例
Aug 24 jQuery
jQuery利用FormData上传文件实现批量上传
Dec 04 jQuery
jQuery实现高度灵活的表单验证功能示例【无UI】
Apr 30 jQuery
jquery实现抽奖功能
Oct 22 jQuery
jquery实现拖拽小方块效果
Dec 10 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批量生成缩略图的代码
2008/07/19 PHP
用sql命令修改数据表中的一个字段为非空(not null)的语句
2010/06/04 PHP
php获取英文姓名首字母的方法
2015/07/13 PHP
PHP实现的二分查找算法实例分析
2017/12/19 PHP
url地址自动加#号问题说明
2010/08/21 Javascript
window.opener用法和用途实例介绍
2013/08/19 Javascript
javascript不同类型数据之间的运算的转换方法
2014/02/13 Javascript
jquery图片滚动放大代码分享(2)
2015/08/28 Javascript
BootStrap3使用错误记录及解决办法
2016/12/22 Javascript
easyui-datagrid开发实践(总结)
2017/08/02 Javascript
Node.js fs模块(文件模块)创建、删除目录(文件)读取写入文件流的方法
2019/09/03 Javascript
利用JS代码自动删除稿件的普通弹幕功能
2019/09/20 Javascript
vue3.0 的 Composition API 的使用示例
2020/10/26 Javascript
[50:48]LGD vs CHAOS 2019国际邀请赛小组赛 BO2 第二场 8.15
2019/08/16 DOTA
用python代码做configure文件
2014/07/20 Python
Python获取运行目录与当前脚本目录的方法
2015/06/01 Python
Python使用 Beanstalkd 做异步任务处理的方法
2018/04/24 Python
Python (Win)readline和tab补全的安装方法
2019/08/27 Python
Python基础之字典常见操作经典实例详解
2020/02/26 Python
解决python 执行sql语句时所传参数含有单引号的问题
2020/06/06 Python
Python-for循环的内部机制
2020/06/12 Python
python3实现名片管理系统(控制台版)
2020/11/29 Python
Python新建项目自动添加介绍和utf-8编码的方法
2020/12/26 Python
HTML5中5个简单实用的API
2014/04/28 HTML / CSS
草莓网美国官网:Strawberrynet USA
2016/12/11 全球购物
GUESS德国官网:美国牛仔服装品牌
2017/02/14 全球购物
法国娇韵诗官方旗舰店:Clarins是来自法国的天然护肤品牌
2018/06/30 全球购物
会计专业个人求职信范文
2014/01/08 职场文书
住院医师规范化培训实施方案
2014/06/12 职场文书
2014年质量工作总结
2014/11/22 职场文书
2014年销售部工作总结
2014/12/01 职场文书
国庆庆典邀请函
2015/02/02 职场文书
2015年城乡环境综合治理工作总结
2015/07/24 职场文书
2016年党建工作简报
2015/11/26 职场文书
《伯牙绝弦》教学反思
2016/02/16 职场文书
大学迎新生的欢迎词
2019/06/25 职场文书