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

jQuery實(shí)現(xiàn)圖片向左向右切換效果的簡單實(shí)例

 更新時(shí)間:2016年05月18日 15:26:38   投稿:jingxian  
下面小編就為大家?guī)硪黄猨Query實(shí)現(xiàn)圖片向左向右切換效果的簡單實(shí)例。小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧

jQuery實(shí)現(xiàn)圖片向左向右切換效果的簡單實(shí)例

<div class="imageRotation container">
  <div class="imageBox">
    <img src="images/chugui.jpg">
    <img src="images/ad_auto.jpg">
    <img src="images/ad_home.jpg">
    <img src="images/ad_nba.jpg">
    <img src="images/ad_stock.jpg">
    <img src="images/ad_yuetu.jpg">
  </div>
  <div class="iconBox">
    <span rel="1" class="active">1</span>
    <span rel="2">2</span>
    <span rel="3">3</span>
    <span rel="4">4</span>
    <span rel="5">5</span>
    <span rel="6">6</span>
  </div>
</div>

 

//CSS樣式

.container {
  width: 1000px;
  margin: 0 auto;
}


.imageRotation {
  width: 1000px;
  height: 480px;
  position: relative;
  overflow: hidden;
  margin-top: 8px;
}


.imageBox {
  position: absolute;
  overflow: hidden;
  display: block;
  height: 480px;
}


.imageBox img {
  width: 1000px;
  height: 480px;
  float: left;
  border: none;
  display: block;
}


.iconBox {
  position: absolute;
  width: 120px;
  height: 12px;
  line-height: 12px;
  top: 444px;
  right: 20px;
  text-align: center;
}


.iconBox span {
  width: 6px;
  height: 6px;
  border-radius: 10px;
  text-align: center;
  background: #555;
  border: 2px solid #f5f5f5;
  float: left;
  text-indent: -999em;
  margin-left: 5px;
  cursor: pointer;
}


.iconBox span.active {
  width: 6px;
  height: 6px;
  background: #820000;
  border-radius: 10px;
  text-align: center;
  text-indent: -999em;
}

 

//js邏輯

$(function() {
  $(".imageRotation").each(function() {
    var imageRotation = this,
    imageBox = $(imageRotation).children(".imageBox"), 
    iconBox = $(imageRotation).children(".iconBox"), 
    iconArr = $(iconBox).children(), 
    imageWidth = $(imageRotation).width(), 

    imageNum = $(imageBox).children().size(), 
    imageRollWidth = imageWidth * imageNum,

    activeID = parseInt($($(iconBox).children(".active")).attr("rel")),

    nextID = 0; 
    var setIntervalID,
    setIntervalTime = 3000,
    speed = 500;



  //設(shè)置 圖片容器 的寬度
  $(imageBox).css({
    'width': imageRollWidth + "px"

  });

  //圖片切換函數(shù)
  function imageRoll(clickID) {
    if (clickID) {
    nextID = clickID;
    } else {
      if (activeID <= 5) {
        nextID = activeID + 1
      } else {
    nextID = 1;
      }
    }

    //圖標(biāo)添加樣式、刪除樣式
    $(iconArr[activeID - 1]).removeClass("active");
    $(iconArr[nextID - 1]).addClass("active");

    $(imageBox).animate({
      left: "-" + (nextID - 1) * imageWidth + "px"

    }, speed);
    activeID = nextID;
  }

  setIntervalID = setInterval(imageRoll, setIntervalTime);

  //鼠標(biāo)移動(dòng)事件
  $(imageBox).hover(function() {
    clearInterval(setIntervalID);
  }, function() {
  setIntervalID = setInterval(imageRoll, setIntervalTime);
});

    //鼠標(biāo)點(diǎn)擊事件
    $(iconArr).click(function() {
      clearInterval(setIntervalID);
      var clickID = parseInt($(this).attr("rel")); //獲取當(dāng)前點(diǎn)擊圖片的id
      imageRoll(clickID);
      setIntervalID = setInterval(imageRoll, setIntervalTime);
      });
   });
});

以上這篇jQuery實(shí)現(xiàn)圖片向左向右切換效果的簡單實(shí)例就是小編分享給大家的全部內(nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論

肇东市| 垦利县| 余干县| 章丘市| 灵台县| 会理县| 七台河市| 阜南县| 安岳县| 阜新| 宜昌市| 青川县| 贵州省| 淅川县| 凤山市| 古浪县| 金昌市| 江达县| 蒲城县| 海口市| 阿勒泰市| 徐水县| 康乐县| 元阳县| 柳江县| 淄博市| 科尔| 海丰县| 荥经县| 巴东县| 海门市| 昌黎县| 昆明市| 杂多县| 渭南市| 巴彦淖尔市| 阿图什市| 长寿区| 丽水市| 彝良县| 玉环县|