溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

js仿京東輪播效果 選項卡套選項卡使用

發布時間:2020-08-29 23:10:23 來源:腳本之家 閱讀:161 作者:光明大神棍 欄目:web開發

本文實例為大家分享了js仿京東輪播效果的具體代碼,實現選項卡套用選項卡,供大家參考,具體內容如下

效果圖:

js仿京東輪播效果 選項卡套選項卡使用

代碼:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>無標題文檔</title>
<style>
*{margin:0;padding:0;}
ul{list-style:none;}img{border:0;}
#tab{width:1000px;height:500px;margin:50px auto;}
#tab .title {width:200px;height:500px;display:inline-block;}
#tab .title li {width:200px;height:125px;float:left;line-height:125px;text-align:center;font-size:30px;background:#f1f1f1;border-bottom:1px dotted #000;}
#tab .title li.active {background:#fff;}
#tab .title li:hover{background:#fff;}
#tab .content {width:799px;height:500px;float:right;display:inline-block;position:relative;border:none;border:none;}
#tab .content img{position:absolute;top:0;left:0;width:799px;height:500px;}
#tab .content ul {position:absolute;width:799px;height:45px;bottom:0;left:0;filter(alpha:80);opacity:0.8;background:#000;}
#tab .content ul li {float:left;height:45px;line-height:45px;background:#d5d5d5;border-right:1px solid #fff;cursor:pointer;text-align:center;}
#tab .content ul li.active {background:red;}
#tab .content ul li:hover{background:red;}
</style>
<script>
window.onload = function () {
 var tab = document.getElementById('tab');
 var title = tab.getElementsByClassName('title')[0];
 var titleLi = title.getElementsByTagName('li');
 var main = tab.getElementsByClassName('main')[0];
 var img = main.getElementsByTagName('img')[0];
 var ul = main.getElementsByTagName('ul')[0];
 var subtitleLi = ul.getElementsByTagName('li');
 var arr = [
  {
   title : '最熱團購',
   subtitle : ['最熱團購1','最熱團購2','最熱團購3'],
   pic : [
    'img/tab/1-1.png',
    'img/tab/1-2.png',
    'img/tab/1-3.png'
   ]
  },
  {
   title : '商城特惠',
   subtitle : ['商城特惠1','商城特惠2','商城特惠3','商城特惠4'],
   pic : [
    'img/tab/2-1.png',
    'img/tab/2-2.png',
    'img/tab/2-3.png',
    'img/tab/2-4.png'
   ]
  },
  {
   title : '名品推薦',
   subtitle : ['名品推薦1','名品推薦2','名品推薦3','名品推薦4','名品推薦5'],
   pic : [
    'img/tab/3-1.png',
    'img/tab/3-2.png',
    'img/tab/3-3.png',
    'img/tab/3-4.png',
    'img/tab/3-5.png'
   ]
  },
  {
   title : '繽紛活動',
   subtitle : ['繽紛活動1','繽紛活動2','繽紛活動3','繽紛活動4'],
   pic : [
    'img/tab/4-1.png',
    'img/tab/4-2.png',
    'img/tab/4-3.png',
    'img/tab/4-3.png',
   ]
  }
 ];

 // 初始化
 for ( var i = 0; i < arr.length; i++ ) {
  // 大選項卡的標題
  var oLi = document.createElement('li');
  oLi.innerHTML = arr[i].title;
  oLi.index = i;
  oLi.onclick = function () {
   highlight(this);
   ul.innerHTML = '';
   changeTab(this.index);
  }
  title.appendChild(oLi);
 }
 changeTab(0);
 function changeTab(num) { 
  // 大選項卡的內容
  img.src = arr[num].pic[1];
  // 小標題
  for ( var j = 0; j < arr[num].subtitle.length; j++ ) {
   oLi = document.createElement('li');
   oLi.innerHTML = arr[num].subtitle[j];
   oLi.style.width = Math.floor(parseInt(800 / arr[num].subtitle.length) - 2) + 'px';
   oLi.index = j;
   oLi.onclick = function () {
    highlight(this);
    this.parentNode.previousElementSibling.src = arr[num].pic[this.index];
   }
   ul.appendChild(oLi);
  }
 }
 function highlight (ele) {
  var aLi = ele.parentNode.children;
  for ( var i = 0; i < aLi.length; i++ ){
     aLi[i].className = '';
  }
  ele.className = 'active';
 }
}
</script>
</head>
<body>
<div id="tab">
 <ul class="title">
 </ul>
 <div class="content">
  <div class="main">
   <img>
   <ul>
   </ul>
  </div>
 </div>
</div>
</body>
</html>

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持億速云。

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女