最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

原生js編寫焦點(diǎn)圖效果

 更新時(shí)間:2016年12月08日 14:58:49   作者:不羈的狂魚  
這篇文章主要為大家詳細(xì)介紹了原生js編寫焦點(diǎn)圖效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

自己用原生js寫的簡(jiǎn)單焦點(diǎn)圖,算是對(duì)原生js初步運(yùn)用。


html部分

<div class="focusPicture">
          <section class="mPhoto" id="mPhoto">
            <img src="images/20161021/b_5809b93b66d18.jpg"/>
          </section><!-- 主要的大圖 -->
          <section class="oPhoto">
            <div class="imgWrap">
              <section class="on">
                <img src="images/20161021/b_5809b93b66d18.jpg"/>
              </section>
              <section>
                <img src="images/20161021/b_5809b96c4da53.jpg"/>
              </section>
              <section>
                <img src="images/20161021/b_5809b9bea39c4.jpg"/>
              </section>
              <section>
                <img src="images/20161021/b_5809ba288384e.jpg"/>
              </section>
              <section>
                <img src="images/20161021/b_5809bae42fa81.jpg"/>
              </section>
              <section>
                <img src="images/20161021/b_5809ba288384e.jpg"/>
              </section>
              <section>
                <img src="images/20161021/b_5809bb3da0bbc.jpg"/>
              </section>
            </div>
          </section><!-- 其他的小圖 -->
          <section class="prevNext">
            <div class="prev">
              <i></i>
            </div><!-- 上一張 -->
            <div class="next">
              <i></i>
            </div><!-- 下一張 -->
          </section><!-- 上下翻頁(yè) -->
</div><!-- 焦點(diǎn)圖區(qū) -->

js部分

window.onload = function(){


 /*焦點(diǎn)圖特效*/
 var mPhoto = document.getElementById("mPhoto");
 var imgWrap = document.getElementsByClassName("imgWrap")[0];
 var wrapSize = 4; /*圖片容器最大顯示圖片數(shù)*/
 if(imgWrap.getElementsByTagName("section").length>wrapSize){
  imgWrap.innerHTML = imgWrap.innerHTML+imgWrap.innerHTML;
 }
 
 var oImages = imgWrap.getElementsByTagName("section");
 for(var i = 0 ; i<oImages.length; i++)
 {
  oImages[i].onmouseover = function()
  {
   for(var j = 0 ; j<oImages.length; j++)
   {
    removeClass(oImages[j],"on");
   }
   var imgSrc = this.getElementsByTagName("img")[0].src;
   addClass(this,"on");
   mPhoto.getElementsByTagName("img")[0].src = imgSrc;
  }
 }


 /*上下翻頁(yè)容器*/
 var oPrevNext = document.getElementsByClassName("prevNext")[0];
 var oPrev = oPrevNext.getElementsByClassName("prev")[0];
 var oNext = oPrevNext.getElementsByClassName("next")[0];
 var oImageHeight = oImages[0].getElementsByTagName("img")[0].height||0;
 var oPositionTop = imgWrap.offsetTop;
 var imgIndex = 0;
 
 if(oImages.length>wrapSize*2)
 {
  oPrev.style.display = "block";
  oNext.style.display = "block";
 }
 
 /*上一頁(yè)*/
 oPrev.onclick=function()
 {
  imgIndex-=1;
  if(imgIndex<=0){
   imgIndex = 6;
  }


  var oTop = imgIndex*(oImageHeight+8);
  imgWrap.style.top = -oTop+"px";
  
  /*獲取當(dāng)前圖片的索引*/
  for(var i = 0 ; i<oImages.length; i++)
  {
   var oBol = hasClass(oImages[i],"on")||false;
   if(oBol){
    var index = oIndex(oImages[i],oImages);
    index=index-1;
    if(imgIndex==6){
     index = 6;
    }
    for(var j = 0 ; j<oImages.length; j++)
    {/*清除其他的圖片on樣式*/
     removeClass(oImages[j],"on");
    }
    addClass(oImages[index],"on");
    var imgSrc = oImages[index].getElementsByTagName("img")[0].src;
    mPhoto.getElementsByTagName("img")[0].src = imgSrc;


    return false;
   }
  }
 }
 
 /*下一頁(yè)*/
 oNext.onclick = function()
 {
  imgIndex+=1;
  if(imgIndex>=6){
   imgIndex = 0;
  }
  var oTop = imgIndex*(oImageHeight+8);
  imgWrap.style.top = -oTop+"px";
  
  /*獲取當(dāng)前圖片的索引*/
  for(var i = 0 ; i<oImages.length; i++)
  {
   var oBol = hasClass(oImages[i],"on")||false;
   if(oBol){
    var index = oIndex(oImages[i],oImages);
    index=index+1;
    if(imgIndex==0){
     index = 1;
    }
    for(var j = 0 ; j<oImages.length; j++)
    {/*清除其他的圖片on樣式*/
     removeClass(oImages[j],"on");
    }
    addClass(oImages[index],"on");
    var imgSrc = oImages[index].getElementsByTagName("img")[0].src;
    mPhoto.getElementsByTagName("img")[0].src = imgSrc;


    return false;
   }
  }


 }
}


function hasClass(element,cName)
{//檢查class是否存在
 return !!element.className.match(new RegExp('(\\s|^)'+cName+'(\\s|$)'));
}
function addClass(element,cName)
{//添加一個(gè)class
 if(!hasClass(element,cName))
 {
  element.className +=' '+cName;
 }
}
function removeClass(element,cName)
{//移除一個(gè)class
 if(hasClass(element,cName))
 {
  element.className = element.className.replace(new RegExp('(\\s|^)'+cName+'(\\s|$)'),' ');
 }
}


function oIndex(current, obj)
{/*獲取索引*/
 for (var i = 0, length = obj.length; i<length; i++)
 { 
  if (obj[i] == current)
  { 
   return 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;
}

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • NestJs 靜態(tài)目錄配置詳解

    NestJs 靜態(tài)目錄配置詳解

    這篇文章主要介紹了NestJs 靜態(tài)目錄配置,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-03-03
  • JavaScript中的6種變體函數(shù)的區(qū)別和應(yīng)用

    JavaScript中的6種變體函數(shù)的區(qū)別和應(yīng)用

    JavaScript?中函數(shù)調(diào)用有許多獨(dú)特的變體方式,例如?~function、-function?等,這些變體不僅展現(xiàn)了?JavaScript?語(yǔ)言的靈活性,也可以在某些場(chǎng)景下讓代碼更加簡(jiǎn)潔,本文將通過(guò)示例代碼和解析,來(lái)全面剖析這些特殊的函數(shù)調(diào)用方式及其返回值的區(qū)別
    2025-01-01
  • Js自定義多選框效果的實(shí)例代碼

    Js自定義多選框效果的實(shí)例代碼

    本篇文章主要介紹了Js自定義多選效果的實(shí)例代碼,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-07-07
  • 使用Javascript接收get傳遞的值的代碼

    使用Javascript接收get傳遞的值的代碼

    用js獲取頁(yè)面值得仿佛,需要的朋友可以參考下。
    2011-11-11
  • IE7提供XMLHttpRequest對(duì)象為兼容

    IE7提供XMLHttpRequest對(duì)象為兼容

    IE7提供XMLHttpRequest對(duì)象為兼容...
    2007-03-03
  • js類型檢查實(shí)現(xiàn)代碼

    js類型檢查實(shí)現(xiàn)代碼

    檢查對(duì)象類型的一種方式是參考所有JavaScript對(duì)象所共有的一個(gè)稱為constructor的屬性。該屬性是對(duì)一個(gè)最初用來(lái)構(gòu)造此對(duì)象的函數(shù)的引用。
    2010-10-10
  • 你知道該如何捕獲js報(bào)錯(cuò)前的用戶行為嗎

    你知道該如何捕獲js報(bào)錯(cuò)前的用戶行為嗎

    這篇文章主要給大家介紹了該如何捕獲js報(bào)錯(cuò)前的用戶行為的相關(guān)資料,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2023-06-06
  • JS實(shí)現(xiàn)電話號(hào)碼的字母組合算法示例

    JS實(shí)現(xiàn)電話號(hào)碼的字母組合算法示例

    這篇文章主要介紹了JS實(shí)現(xiàn)電話號(hào)碼的字母組合算法,結(jié)合實(shí)例形式分析了javascript組合運(yùn)算的相關(guān)算法原理與操作技巧,需要的朋友可以參考下
    2019-02-02
  • JS設(shè)計(jì)模式之策略模式概念與用法分析

    JS設(shè)計(jì)模式之策略模式概念與用法分析

    這篇文章主要介紹了JS設(shè)計(jì)模式之策略模式概念與用法,簡(jiǎn)單分析了策略模式的基本概念、原理并結(jié)合實(shí)例形式分析了javascript實(shí)現(xiàn)與使用策略模式的相關(guān)操作技巧,需要的朋友可以參考下
    2018-02-02
  • 小程序animate動(dòng)畫實(shí)現(xiàn)直播間點(diǎn)贊

    小程序animate動(dòng)畫實(shí)現(xiàn)直播間點(diǎn)贊

    這篇文章主要為大家詳細(xì)介紹了小程序animate動(dòng)畫實(shí)現(xiàn)直播間點(diǎn)贊,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-07-07

最新評(píng)論

平湖市| 潍坊市| 广州市| 长丰县| 通海县| 兖州市| 阳朔县| 花莲市| 英德市| 卫辉市| 湘阴县| 潼南县| 伊金霍洛旗| 陇川县| 石河子市| 巴林右旗| 安徽省| 屏东市| 嘉义市| 抚顺市| 涿州市| 灵丘县| 德令哈市| 阜新| 宕昌县| 小金县| 邻水| 新兴县| 绥芬河市| 蒙阴县| 开平市| 奉新县| 固阳县| 宁晋县| 澳门| 遵义县| 衡阳市| 集安市| 恩施市| 洱源县| 邯郸县|