轮播图html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>shili</title>
<link rel="stylesheet" href="css/yangshi.css">
</head>
<body>
<div class="main" id="main">
<div class="menu-box"></div>
<!--子菜单-->
<div class="sub-menu hide" id="sub-menu">
<div class="inner-box">
<div class="sub-inner-box">
<div class="title">手机配件</div>
<div class="sub-row">
<span class="blod mr10">手机品牌:</span>
<a href="">OPPO手机</a>
<span class="mr10 ml10">/</span>
<a href="">Vivo手机</a>
<span class="mr10 ml10">/</span>
<a href="">魅族手机</a>
<span class="mr10 ml10">/</span>
<a href="">中兴手机</a>
<span class="mr10 ml10">/</span>
<a href="">联想手机</a>
<span class="mr10 ml10">/</span>
<a href="">苹果手机</a>
</div>
<div class="sub-row">
<span class="blod mr10">手机通讯商:</span>
<a href="">中国联通</a>
<span class="mr10 ml10">/</span>
<a href="">中国电信</a>
<span class="mr10 ml10">/</span>
<a href="">中国移动</a>
</div>
<div class="sub-row">
<span class="blod mr10">手机网络:</span>
<a href="">3G</a>
<span class="mr10 ml10">/</span>
<a href="">4G</a>
<span class="mr10 ml10">/</span>
<a href="">5G</a>
</div>
<div class="sub-row">
<span class="blod mr10">手机外设:</span>
<a href="">手机壳</a>
<span class="mr10 ml10">/</span>
<a href="">钢化膜</a>
<span class="mr10 ml10">/</span>
<a href="">内存卡</a>
<span class="mr10 ml10">/</span>
<a href="">手机屏</a>
</div>
<div class="sub-row">
<span class="blod mr10">手机售后:</span>
<a href="">oppo售后</a>
<span class="mr10 ml10">/</span>
<a href="">vivo售后</a>
<span class="mr10 ml10">/</span>
<a href="">联想售后</a>
<span class="mr10 ml10">/</span>
<a href="">苹果售后</a>
</div>
<div class="sub-row">
<span class="blod mr10">手机售后:</span>
<a href="">温馨提醒:除苹果售后服务外,<b>领哥家里蹲公司</b>暂不受理,其他品牌详细资费标准点击查看</a>
</div>
</div>
</div>
<!--电脑子菜单-->
<div class="inner-box">
<div class="sub-inner-box">
<div class="title">电脑配件</div>
<div class="sub-row">
<span class="blod mr10">电脑品牌:</span>
<a href="">联想</a>
<span class="mr10 ml10">/</span>
<a href="">华硕</a>
<span class="mr10 ml10">/</span>
<a href="">中兴</a>
</div>
<div class="sub-row">
<span class="blod mr10">电脑通讯:</span>
<a href="">电脑</a>
<span class="mr10 ml10">/</span>
<a href="">以旧换新</a>
<span class="mr10 ml10">/</span>
<a href="">新机倒卖</a>
</div>
<div class="sub-row">
<span class="blod mr10">电脑外设:</span>
<a href="">电脑数据线</a>
<span class="mr10 ml10">/</span>
<a href="">电脑钢化膜</a>
<span class="mr10 ml10">/</span>
<a href="">内存卡</a>
<span class="mr10 ml10">/</span>
<a href="">电脑屏</a>
</div>
<div class="sub-row">
<span class="blod mr10">电脑售后:</span>
<a href="">电脑屏幕问题</a>
<span class="mr10 ml10">/</span>
<a href="">电脑电源问题</a>
<span class="mr10 ml10">/</span>
<a href="">硬盘问题</a>
<span class="mr10 ml10">/</span>
<a href="">电脑系统问题</a>
</div>
</div>
</div>
<!--家用电器子菜单-->
<div class="inner-box">
<div class="sub-inner-box">
<div class="title">家用电器</div>
<div class="sub-row">
<span class="blod mr10">洗衣机类:</span>
<a href="">海尔</a>
<span class="mr10 ml10">/</span>
<a href="">美的</a>
<span class="mr10 ml10">/</span>
<a href="">格力</a>
</div>
<div class="sub-row">
<span class="blod mr10">电饭煲类:</span>
<a href="">便宜</a>
<span class="mr10 ml10">/</span>
<a href="">中端</a>
<span class="mr10 ml10">/</span>
<a href="">优质</a>
<span class="mr10 ml10">/</span>
<a href="">高端</a>
</div>
</div>
</div>
<!--家具子菜单-->
<div class="inner-box">
<div class="sub-inner-box">
<div class="title">首饰</div>
<div class="sub-row">
<span class="blod mr10">手镯:</span>
<a href="">翡翠</a>
<span class="mr10 ml10">/</span>
<a href="">上等玉</a>
<span class="mr10 ml10">/</span>
<a href="">珍珠</a>
</div>
<div class="sub-row">
<span class="blod mr10">耳环:</span>
<a href="">银</a>
<span class="mr10 ml10">/</span>
<a href="">金</a>
<span class="mr10 ml10">/</span>
<a href="">宝石</a>
<span class="mr10 ml10">/</span>
<a href="">金刚石</a>
<span class="mr10 ml10">/</span>
<a href="">翡翠</a>
</div>
<div class="sub-row">
<span class="blod mr10">项链:</span>
<a href="">银</a>
<span class="mr10 ml10">/</span>
<a href="">金</a>
<span class="mr10 ml10">/</span>
<a href="">宝石</a>
<span class="mr10 ml10">/</span>
<a href="">金刚石</a>
<span class="mr10 ml10">/</span>
<a href="">翡翠</a>
</div>
<div class="sub-row">
<span class="blod mr10">脚链:</span>
<a href="">银</a>
<span class="mr10 ml10">/</span>
<a href="">金</a>
<span class="mr10 ml10">/</span>
<a href="">宝石</a>
<span class="mr10 ml10">/</span>
<a href="">金刚石</a>
<span class="mr10 ml10">/</span>
<a href="">翡翠</a>
</div>
<div class="sub-row">
<span class="blod mr10">手环:</span>
<a href="">银</a>
<span class="mr10 ml10">/</span>
<a href="">金</a>
<span class="mr10 ml10">/</span>
<a href="">宝石</a>
<span class="mr10 ml10">/</span>
<a href="">金刚石</a>
<span class="mr10 ml10">/</span>
<a href="">翡翠</a>
</div>
<div class="sub-row">
<span class="blod mr10">耳坠:</span>
<a href="">银</a>
<span class="mr10 ml10">/</span>
<a href="">金</a>
<span class="mr10 ml10">/</span>
<a href="">宝石</a>
<span class="mr10 ml10">/</span>
<a href="">金刚石</a>
<span class="mr10 ml10">/</span>
<a href="">翡翠</a>
</div>
</div>
</div>
</div>
<!--主菜单-->
<div class="menu-content" id="menu-content">
<div class="menu-item">
<a href="">
<span>手机配件</span>
<i></i>
</a>
</div>
<div class="menu-item">
<a href="">
<span>电脑</span>
<i></i>
</a>
</div>
<div class="menu-item">
<a href="">
<span>家用电器</span>
<i></i>
</a>
</div>
<div class="menu-item">
<a href="">
<span>首饰</span>
<i></i>
</a>
</div>
</div>
<!--轮播图-->
<div class="banner" id="banner">
<a href=""><div class="banner-slide slide1 slide-active"></div></a>
<a href=""><div class="banner-slide slide2"></div></a>
<a href=""><div class="banner-slide slide3"></div></a>
</div>
<!--上一张,下一张,切换按钮-->
<a href="javascript:void(0)" class="buttom prev" id="prev"></a>
<a href="javascript:void(0)" class="buttom next" id="next"></a>
<!--底部小圆点-->
<div class="dots" id="dots">
<span class="active"></span>
<span></span>
<span></span>
</div>
</div>
<script src="js/script.js"></script>
</body>
</html>
轮播图js
function byId(id){
return typeof (id) === "string" ? document.getElementById(id):id;
}
var index=0;
var timer=null,
pics=byId("banner").getElementsByTagName("div"),
len=pics.length,
dots=byId("dots").getElementsByTagName("span"),
prev=byId("prev"),
next=byId("next"),
menu=byId("menu-content"),
subMenu=byId("sub-menu"),
innerBox=subMenu.getElementsByClassName("inner-box"),
menuItems=menu.getElementsByClassName("menu-item");
function slideImg(){
var main = byId("main");
main.οnmοuseοver=function(){
if (timer) clearInterval(timer);
}
main.οnmοuseοut=function(){
timer=setInterval(function(){
index++;if (index>=len) {index=0}
changeImg();
},3000);
}
main.onmouseout();
//点击原点切换图片;
for (var d=0; d<len; d++) {
dots[d].id=d;
dots[d].οnclick=function(){
index=this.id;
changeImg();
}
}
//导航菜单
//遍历菜单
for (var m=0; m<menuItems.length;m++) {
menuItems[m].setAttribute("data-index",m);
menuItems[m].οnmοuseοver= function(){
subMenu.className="sub-menu";
var idx=this.getAttribute("data-index");
for (var j= 0; j<innerBox.length;j++) {
innerBox[j].style.display='none';
menuItems[j].style.background='none';
}
menuItems[idx].style.background='rgba(0,0,0,0.2)';
innerBox[idx].style.display='block';
}
}
menu.οnmοuseοut=function(){
subMenu.className="sub-menu hide";
}
subMenu.οnmοuseοver=function(){
this.className="sub-menu";
}
subMenu.οnmοuseοut=function(){
this.className="sub-menu hide";
}
//点击按钮切换图片
next.οnclick=function(){
index++;
if (index>=len) index=0;
changeImg();
}
//上一张
prev.οnclick=function(){
index--;
if (index<0) index=len-1;
changeImg();
}
}
//切换函数
function changeImg(){
//遍历banner下有多少个div及dots下的span,将div隐藏将span清楚类
for (var i=0;i<len;i++) {
pics[i].style.display="none";
dots[i].className="";
}
//根据当前index找到当前div及span,将其显示出来和设置为当前。
pics[index].style.display="block";
dots[index].className="active";
}
slideImg();
轮播图css样式:
*{margin: 0px;padding: 0px;}
body{
font-family: "微软雅黑",color:#14191e;
}
ul{list-style: none;}
@font-face{
font-family: "iconfont";
src:url("../img/font/iconfont.eot");
src:url("../img/font/iconfont.eot") format("embedded-opentype"),
url("../img/font/iconfont.woff") format("woff"),
url("../img/font/iconfont.ttf") format("truetype"),
url("../img/font/iconfont.svg#iconfog") format("svg");
}
.main{width: 1200px;height: 460px;margin: 30px auto;
overflow: hidden;position: relative;}
.banner{width: 1200px;height: 460px;position:relative;}
.banner-slide{width: 1200px;height: 460px;
position:absolute;
background-repeat: no-repeat;
display: none;
}
.slide1{background-image:url("../img/bg1.jpg"); }
.slide2{background-image:url("../img/bg2.jpg"); }
.slide3{background-image:url("../img/bg3.jpg"); }
.slide-active{display: block;}
.buttom{position: absolute;width: 40px;
height: 80px;top:50%;margin-top:-40px;left: 244px;
background: url("../img/arrow.png") no-repeat center center;
}
.buttom:hover{background-color:#333;
opacity: 0.7;
filter: alpha(opacity=70); }
.prev{transform: rotate(180deg);}
.next{left:auto;right: 0px;}
.dots{position: absolute;
right: 20px;bottom: 24px;text-align: right; }
.dots span{display:inline-block;background: rgba(7,17,27,0.4);
box-shadow:0 0 0 2px rgba(277,277,277,0.8) inset;width: 12px;
height: 12px;line-height: 12px;
border-radius:50%;margin-left:9px;cursor: pointer;}
.dots span.active{box-shadow:0 0 0 2px rgba(277,277,277,0.8) inset;
background: #fff;}
/*侧边框*/
.menu-box{width: 244px;height: 460px;
position: absolute;
left:0;top:0;
z-index:1;
background: rgba(7,17,27,0.5);
opacity: 0.5;}
.menu-content{width: 244px;
height: 454px;
position: absolute;
left:0;top:0;
z-index:2;
padding-top:6px; }
.menu-item{height: 64px;
line-height: 66px;
font-size: 16px;
padding: 0 24px;
position: relative;
}
.menu-item a:link,.menu-item a:visited{
color: #fff;
}
.menu-item a{display: block;
border-bottom: 1px solid rgba(255,255,255,0.6);
padding:0 10px;
height: 63px;
text-decoration:none;
}
.menu-item i{
position: absolute;
font-size: 24px;
right: 32px;
top: 2px;
font-family: iconfont;
font-style: normal;
font-weight: normal;
}
.sub-menu{width: 730px;
height: 458px;
border: 1px solid #d9dde1;
position: absolute;
background: #fff;
top: 0px;
left: 244px;
z-index: 6;
box-shadow: 0 4px 8px 0 rgba("0,0,0,0.1");
}
.inner-box{
width: 100%;
height: 100%;
background: url(../img/fe.png) no-repeat;
display: none;
}
.sub-inner-box{
width: 652px;
margin-left:40px;
overflow: hidden;
}
.title{color: #f01414;
font-size: 16px;
line-height: 16px;
margin: 28px 0 30px 0;
font-weight: bold;
}
.sub-row{margin-bottom:25px; }
.blod{font-weight: bold;}
.mr10{margin-right:10px; }
.ml10{margin-left:10px; }
.sub-row a{text-decoration:none;}
.hide{display: none;}
结果展示:
![](https://i-blog.csdnimg.cn/blog_migrate/4c244bd211557462a636b339ac4e8a9a.png)
![](https://i-blog.csdnimg.cn/blog_migrate/1c170c1bd5d3c415beb3c0057a6b5321.png)