欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

js实现产品缩略图效果

程序员文章站 2022-09-30 08:38:11
效果图: 代码如下:

效果图:

js实现产品缩略图效果

代码如下:

<!doctype html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<script src="http://how2j.cn/study/js/jquery/2.0.0/jquery.min.js"></script>
<link href="http://how2j.cn/study/css/bootstrap/3.3.6/bootstrap.min.css" rel="external nofollow" rel="stylesheet">
<script src="http://how2j.cn/study/js/bootstrap/3.3.6/bootstrap.min.js"></script>
</head>
<script>
$(function(){
 $("img.smallimage").mouseenter(function(){
  var bigimageurl = $(this).attr("bigimageurl");
  $("img.bigimg").attr("src",bigimageurl);
 });
 $("img.bigimg").load(
  function(){
   $("img.smallimage").each(function(){
    var bigimageurl = $(this).attr("bigimageurl");
    img = new image();
    img.src = bigimageurl;
    img.onload = function(){
     console.log(bigimageurl); 
     $("div.img4load").append($(img));
    };
   });  
  }
 );
});
</script>
<style>
div.imgandinfo{
 margin: 40px 20px;
}
div.imginimgandinfo{
 width: 400px;
 float: left;
}
div.imgandinfo img.bigimg{
 width: 400px;
 height: 400px;
 padding: 20px;
 border: 1px solid #f2f2f2;
}
div.imgandinfo div.smallimagediv{
 width: 80%;
 margin: 20px auto;
}
div.imgandinfo img.smallimage{
 width: 60px;
 height: 60px;
 border: 2px solid white;
}
div.imgandinfo img.smallimage:hover{
 border: 2px solid black;
}
</style>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<div class="imgandinfo">
 <div class="imginimgandinfo">
  <img width="100px" class="bigimg" src="http://how2j.cn/tmall/img/productsingle/8619.jpg">
  <div class="smallimagediv">
    <img width="100px" class="smallimage" src="http://how2j.cn/tmall/img/productsingle_small/8620.jpg" bigimageurl="http://how2j.cn/tmall/img/productsingle/8620.jpg">
    <img width="100px" class="smallimage" src="http://how2j.cn/tmall/img/productsingle_small/8619.jpg" bigimageurl="http://how2j.cn/tmall/img/productsingle/8619.jpg">
    <img width="100px" class="smallimage" src="http://how2j.cn/tmall/img/productsingle_small/8618.jpg" bigimageurl="http://how2j.cn/tmall/img/productsingle/8618.jpg">
    <img width="100px" class="smallimage" src="http://how2j.cn/tmall/img/productsingle_small/8617.jpg" bigimageurl="http://how2j.cn/tmall/img/productsingle/8617.jpg">
    <img width="100px" class="smallimage" src="http://how2j.cn/tmall/img/productsingle_small/8616.jpg" bigimageurl="http://how2j.cn/tmall/img/productsingle/8616.jpg">
  </div>
 <div class="img4load hidden" ></div>  
 </div>
 <div style="clear:both"></div>
</div>

以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,同时也希望多多支持!