成人精品一区二区三区中文字幕-成人精品一区二区三区-成人精品一级毛片-成人精品亚洲-日本在线视频一区二区-日本在线视频免费

導(dǎo)航首頁 ? 技術(shù)教程 ? jQuery實(shí)現(xiàn)圖片向左向右切換效果的簡單實(shí)例
全站頭部文字 我要出現(xiàn)在這里
jQuery實(shí)現(xiàn)圖片向左向右切換效果的簡單實(shí)例 653 2024-03-04   

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

<div class="imageRotation container">
  <div class="imageBox">
    <img src="http://www.gimoo.net/t/1903/images/chugui.jpg">
    <img src="http://www.gimoo.net/t/1903/images/ad_auto.jpg">
    <img src="http://www.gimoo.net/t/1903/images/ad_home.jpg">
    <img src="http://www.gimoo.net/t/1903/images/ad_nba.jpg">
    <img src="http://www.gimoo.net/t/1903/images/ad_stock.jpg">
    <img src="http://www.gimoo.net/t/1903/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è)參考,也希望大家多多支持綠夏網(wǎng)。



主站蜘蛛池模板: 七令诡事录 电影| 周末的一天| 青春没有遗憾才完美辩论资料| 日本电影家庭教师| 女同性恋视频网站| 古建凉亭生产厂家| 亲密 电影| 凤凰卫视资讯台直播| 长句变短句的例题| 爱情三选一| 烟草甲虫| bernadette| cctv16节目表今天内容| 春江花月夜理解性默写及答案| 寡妇电影| 赵艳红| 水浒传新| 德鲁| 皇家香港警察| 豪门本色| 富含维生素c的水果和蔬菜| 天云山传奇 电影| 浙江卫视今日节目表| 消防知识问答100题| 艳妇乳肉豪妇荡乳ⅹxxoo韩国| 郭碧婷是哪里人| 甜蜜都市| 妈妈的脊背简谱| 6套电影频道节目表| 洞房奇谭电影免费版在线观看| 电影《七天》| 又造句二年级上册| 红海行动2虎鲸行动| 郎雄| 铃木纱理奈| bbbbbbbbb免费毛片视频| 龙八夷| 香港卫视中文台| 南方车站的聚会| 抖音网页版登录| 省港旗兵1|

!!!站長長期在線接!!!

網(wǎng)站、小程序:定制開發(fā)/二次開發(fā)/仿制開發(fā)等

各種疑難雜癥解決/定制接口/定制采集等

站長微信:lxwl520520

站長QQ:1737366103