栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > Web开发 > JavaScript

原生js编写焦点图效果

JavaScript 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

原生js编写焦点图效果

自己用原生js写的简单焦点图,算是对原生js初步运用。


html部分


   

js部分

window.onload = function(){


 
 var mPhoto = document.getElementById("mPhoto");
 var imgWrap = document.getElementsByClassName("imgWrap")[0];
 var wrapSize = 4; 
 if(imgWrap.getElementsByTagName("section").length>wrapSize){
  imgWrap.innerHTML = imgWrap.innerHTML+imgWrap.innerHTML;
 }
 
 var oImages = imgWrap.getElementsByTagName("section");
 for(var i = 0 ; iwrapSize*2)
 {
  oPrev.style.display = "block";
  oNext.style.display = "block";
 }
 
 
 oPrev.onclick=function()
 {
  imgIndex-=1;
  if(imgIndex<=0){
   imgIndex = 6;
  }


  var oTop = imgIndex*(oImageHeight+8);
  imgWrap.style.top = -oTop+"px";
  
  
  for(var i = 0 ; i=6){
   imgIndex = 0;
  }
  var oTop = imgIndex*(oImageHeight+8);
  imgWrap.style.top = -oTop+"px";
  
  
  for(var i = 0 ; i

css部分

.productInfo .focusPicture{
 width: 698px;
 float: left;
 position: relative;
 border-right: 1px solid #d9cdb4;
}
.productInfo .focusPicture .mPhoto{
 width: 542px;
 height: 360px;


}
.productInfo .focusPicture .mPhoto img{
 width: 100%;
 height: 100%;
}


.productInfo .focusPicture .oPhoto{
 width: 128px;
 height: 352px;
 position: absolute;
 right: 14px;
 top: 4px;
 overflow: hidden;


}


.productInfo .oPhoto div{
 width: 128px;
 position: absolute;
 left:0;
 top:0;
 -webkit-transition: top .2s ease-out;
 -moz-transition: top .2s ease-out;
 transition: top .2s ease-out; 
}
.productInfo .oPhoto section{
 height: 78px;
 margin: 8px 0;
 position: relative;
 cursor: pointer;
}
.productInfo .oPhoto section::before {
 content: "";
 display: block;
 width: 100%;
 height: 100%;
 background-color: rgba(255,255,255,.42);
 position: absolute;
 left: 0;
 top: 0;
}


.productInfo .oPhoto section.on::before{
 display: none;
}


.productInfo .focusPicture .oPhoto img{
 width: 100%;
 height: 100%;
}


.productInfo .focusPicture .prevNext{
 width: 32px;
 height: 32px;
 position: absolute;
 top: -4px;
 right: 62px;
}


.productInfo .prevNext div.prev,
.productInfo .prevNext div.next{
 width: 32px;
 height: 32px;
 -webkit-border-radius: 50%;
 -moz-border-radius: 50%;
 border-radius: 50%;
 background-color: #fff;
 position: absolute;
 left: 0;
 -webkit-transition: all .25s;
 -moz-transition: all .25s;
 transition: all .25s;
 display: none;
 cursor: pointer;
}
.productInfo .prevNext div.prev{
 top: 0;
 box-shadow: 0 -2px 4px rgba(0,0,0,.24);


}
.productInfo .prevNext div.next{
 top: 336px;
 box-shadow: 0 2px 4px rgba(0,0,0,.24);
}


.productInfo .prevNext div.prev:hover{
 box-shadow: 2px -2px 3px rgba(0,0,0,.24);


}
.productInfo .prevNext div.next:hover{
 box-shadow: -2px 2px 3px rgba(0,0,0,.24);
}


.productInfo .prevNext div.prev i,
.productInfo .prevNext div.next i{
 width: 16px;
 height: 16px;
 position: absolute;
 top: 0;
 right: 0;
 bottom: 0;
 left: 0;
 margin: auto;
 cursor: pointer;
}
.productInfo .prevNext div.prev i{
 background: url(../images/arrows-icon.png) 0 -16px no-repeat;
 background-size: 48px 32px;
 bottom: 2px;
}


.productInfo .prevNext div.next i{
 background: url(../images/arrows-icon.png) 0 0 no-repeat;
 background-size: 48px 32px;
 top: 2px;
}


.productInfo .prevNext div.prev:hover i,
.productInfo .prevNext div.next:hover i{
 -webkit-transform: scale(1.1);
 -moz-transform: scale(1.1);
 transform: scale(1.1);
}


.productInfo .prevNext div.prev:hover i{
 background: url(../images/arrows-icon.png) -16px -16px no-repeat;
 background-size: 48px 32px;
}


.productInfo .prevNext div.next:hover i{
 background: url(../images/arrows-icon.png) -16px 0px no-repeat;
 background-size: 48px 32px;
}


.productInfo .prevNext div.prev:active i{
 background: url(../images/arrows-icon.png) -32px -16px no-repeat;
 background-size: 48px 32px;
}


.productInfo .prevNext div.next:active i{
 background: url(../images/arrows-icon.png) -32px 0px no-repeat;
 background-size: 48px 32px;
}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持考高分网。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/92098.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号