首页 > 其他分享 >js实现产品页点击小图在大图区显示

js实现产品页点击小图在大图区显示

时间:2023-05-09 10:34:54浏览次数:27  
标签:图区 img width js 小图 hd hidden li tempWrap

企业网站产品图片可能会比较多,需要在产品页面多放几张展示图片,我们可以使用一张大图+几张小图的形式排列,并使用js代码实现点击小图显示大图。效果如下所示


html代码部分:
<div class="img_bd">
    <img src="/e/picture/180613/1-1P6130ZH6.jpg" alt=' ' class="img-responsive center-block" id="pic" curindex="0"/>
</div>
<div class="img_hd">
    <div class="tempWrap" style="overflow: hidden; position: relative;">
        <ul style="left: 0px; position: relative; overflow: hidden; padding: 0px; margin: 0px;">
            <li style="float: left;"><img src="/e/picture/180613/1-1P6130ZH6.jpg" data-large="/e/picture/180613/1-1P6130ZH6.jpg" alt=''/></li>
            <li style="float: left;"><img src="/e/picture/180613/1-1P6130ZH6-50.jpg" data-large="/e/picture/180613/1-1P6130ZH6-50.jpg" alt=''/></li>
            <li style="float: left;"><img src="/e/picture/180613/1-1P6130ZH6-51.jpg" data-large="/e/picture/180613/1-1P6130ZH6-51.jpg" alt=''/></li>
            <li style="float: left;"><img src="/e/picture/180613/1-1P6130ZH6-52.jpg" data-large="/e/picture/180613/1-1P6130ZH6-52.jpg" alt=''/></li>
        </ul>
    </div>
</div>

js代码部分:
$(document).ready(function () {
var firstpic = $(".tempWrap ul li").first().find("img");
var firstsrc = firstpic.attr("data-large");
$("#pic").attr("src", firstsrc);
$(".tempWrap ul li").first().addClass("on");
$(".tempWrap img").click(function () {
    $(this).parent().addClass("on").siblings().removeClass("on");
    var imgSrc = $(this).attr("data-large");
    $("#pic").attr("src", imgSrc);
    var currentindex = $(this).parent().index();
    $("#pic").attr("curindex", currentindex);
})
$("#preArrow_B").click(function () {
    preclick()
});
$("#nextArrow_B").click(function () {
    nextclick()
});
});

css代码部分:
.img_bd { width:100%;  height: 220px; overflow: hidden;text-align: center;  position: relative; z-index: 1;}
.img_hd { height: auto;  position: relative; margin-top:15px;overflow: hidden;}
.img_hd  .picmidleft {  float: left;  width: 24px; overflow: hidden;}
.img_hd  .picmidright { float: left; width: 24px;  overflow: hidden;}
.img_hd .picmidleft a ,.img_hd .picmidright a{ background:#fff;color:#1a87d6;display: block; width: 24px; height: 55px; border: 1px solid #cfe2f0; line-height: 55px; font-size: 30px; text-align: center; margin-top:auto;}
.img_hd .picmidleft a:hover ,.img_hd .picmidright a:hover{background:#E3E3E3}
.img_hd .tempWrap{float: left; width: 330px;  overflow: hidden; padding-left: 0px;}
.img_hd  .tempWrap ul { width: 100%; overflow: hidden; position: relative;  margin: 0;}
.img_hd .tempWrap ul li{float: left;margin-top: 1px; display: inline; width: 23%; height: 55px; border: 1px solid #e4eff6;  overflow: hidden; text-align: center; vertical-align: middle;}
.img_hd .tempWrap ul li + li{ margin-left:2%; }
.img_hd .tempWrap ul li img{ width:100%; height:auto;}
.img_hd .tempWrap ul li.on { border: 3px solid #0f6eb5; margin-top: 0px;}
大家也可以根据自己的需求进行调整。

标签:图区,img,width,js,小图,hd,hidden,li,tempWrap
From: https://www.cnblogs.com/akweb/p/17384115.html

相关文章

  • arduino 之 json 再测试(key是否存在)
    1.使用containsKey():Stringdo_back(Stringjson){StaticJsonDocument<200>sjdoc;deserializeJson(sjdoc,json);Stringval=sjdoc["hlf"].as<String>();Serial.print("val:");Serial.println(val);Serial.print("sjdoc.contai......
  • 《nodejs跨栏》命令篇
    npm查看一个包的版本参考链接:https://segmentfault.com/a/1190000022694959注意:CMD命令要以管理员模式启动。#查看npm服务器上所有的jquery版本:dubai@DESKTOP-UFFVH6LMINGW64/$npmviewjqueryversions#查看npm服务器上jquery最新版本:dubai@DESKTOP-UFFVH6LMINGW6......
  • xlsx.js导出表格
    说明vue2前端导出表格需用用到xlsx.js这个库npminstallxlsx实现操作合并单元格把数组导出成excel代码部分wch和import*asXLSXfrom"xlsx";//记得在要用的页面导入/*导出表格*/exportExcel_(){ /*定义表格的数据第一行是表头*/ vardata=[ ["名称",......
  • 【内存分析】用于内存分析定位的指令 jmap, jstat, jinfo, jstack
    用于内存分析定位的指令/工具有:jmap,jstat,jinfo,jstackjmap(1)分析进程中的内存使用情况,是多少个什么样的对象占用了多大的内存,这类型的分析(2)也可以导出堆转储文件,导出后,再来分析jstack这个是看cpu的,看各个线程的执行状态,如果cpu比较高,就是用jstack来定位分析......
  • js中找出对象中值最大的一项
    比如有以下对象constobj={num1:1000,num2:800,num3:900,}期望得到num1:1000这一项。js实现代码:exportconstmaxIncome=(userWalletIncomes)=>{letmaxValue=0;letmaxKey='';for(const[key,value]ofObject.entries(userWalletIncom......
  • 使用 nodejs 从 0 实现简单易用的代理功能之 config.proxy
    从0实现config.proxyconfig.proxy类似于webpack的devServe中的代理,但更直观易用.本文为mockm的实现过程,编写此系列文章1是为了抛砖引玉,让想实现类似工具的朋友可以一起学习.2是也给自己做一个简单梳理.类型:string|object默认:http://www.httpbin.or......
  • 【nodejs基础】Express、路由、中间件详解04
    一、Express简介Express是基于Node.js平台,快速、开放、极简的Web开发框架通俗的理解:Express的作用和Node.js内置的http模块类似,是专门用来创建Web服务器的。本质就是一个npm上的第三方包,提供了快速创建Web服务器的便捷方法中文官网http://www.expressjs.com.cn......
  • Mac安装node.js开发环境的详细步骤
    1.官网下载node.js下载地址:https://nodejs.org/  直接点击下载即可。2.双击刚下载的文件,默认点继续安装就行。3.安装完成后,打开终端,输入“npm-v”和“node-v”两个命令,如下图出现版本信息,说明安装成功。 4.进行环境配置打开终端,输入“open-e.bash_profile”回车,在......
  • JS之根据两地经纬度获得两点之间的距离
    JS之根据两地经纬度获得两点之间的距离:constgetDistance=(lat1,lng1,lat2,lng2)=>{lat1=lat1||0;lng1=lng1||0;lat2=lat2||0;lng2=lng2||0;varrad1=(lat1*Math.PI)/180.0;varrad2=(lat2*Math.PI)/180.0;vara=ra......
  • jsp
        ......