老师,商品区域的轮播图该如何实现,我还没想通,请老师指点
来源:3-2 项目作业
廖可爱bongbong
2021-06-18 16:22:40
相关代码:HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>慕家居——简约、自人性化</title>
<meta name="Keywords" content="北欧简约风,简约,自然,人性化">
<meta name="Description" content="慕家居——北欧简约风、触手可及的家居格调">
<link rel="stylesheet" href="css/reset.css">
<link rel="stylesheet" href="css/base.css">
<link rel="stylesheet" href="css/css.css">
</head>
<body>
<!-- top区域 -->
<div class="topbar clearfix">
<div class="center-wrap">
<p>服务热线:400-8888-888</p>
</div>
</div>
<!-- head区域 -->
<div class="headbar">
<div class="center-wrap">
<div class="logo">
<p>慕家居</p>
</div>
<nav class="headnav center-wrap">
<div class="headpic">
<ul class="clearfix">
<li>
<a href="" class="btn iconfont"></a>
<p>网站首页</p>
</li>
<li>
<a href="" class="btn iconfont"></a>
<p>关于我们</p>
</li>
<li>
<a href="" class="btn iconfont"></a>
<p>服务建设</p>
</li>
<li>
<a href="" class="btn iconfont"></a>
<p>产品中心</p>
</li>
<li>
<a href="" class="btn iconfont"></a>
<p>服务大厅</p>
</li>
</ul>
</div>
</nav>
<div class="soso-box">
<input type="text" placeholder="请输入搜索内容">
<a href="" class="btn iconfont"></a>
</div>
</div>
</div>
<!-- banner区域 -->
<section class="bannerbar center-wrap">
<div class="banner" id="banner">
<img class="active" src="images/banner01.png" alt="">
<img src="images/banner02.png" alt="">
<img src="images/banner03.png" alt="">
</div>
<div class="circles" id="circles">
<!-- data-index="0"是一个自定义的属性,它的作用是标记当前小点的索引 -->
<span data-idex="0" class="active"></span>
<span data-idex="1"></span>
<span data-idex="2"></span>
</div>
</section>
<script src="js/banner.carousel.js"></script>
<!-- 商品区域 -->
<section class="productsbar center-wrap">
<div class="leftbtn" id="left_btn"><a href="javascript:;"></a></div>
<div class="rightbtn" id="right_btn"><a href="javascript:;"></a></div>
<div class="products" id="products">
<div class="products_box">
<dl>
<dt><img src="images/product01.png" alt=""></dt>
<dd>
<p>时尚卫生间墙面颜色</p>
<p>2029装饰设计</p>
</dd>
</dl>
<dl>
<dt><img src="images/product02.png" alt=""></dt>
<dd>
<p>现代北欧风格厨房装</p>
<p>2029饰效果图</p>
</dd>
</dl>
<dl>
<dt><img src="images/product03.png" alt=""></dt>
<dd>
<p>现代时尚北欧风格卧</p>
<p>2029室装饰画</p>
</dd>
</dl>
<dl>
<dt><img src="images/product04.png" alt=""></dt>
<dd>
<p>130平简约现代北欧</p>
<p>2029风格装修</p>
</dd>
</dl>
<dl>
<dt><img src="images/product05.png" alt=""></dt>
<dd>
<p>现代北欧风格小客厅</p>
<p>2029装修设计</p>
</dd>
</dl>
<dl>
<dt><img src="images/product06.png" alt=""></dt>
<dd>
<p>时尚卫生间墙面颜色</p>
<p>2029装饰设计</p>
</dd>
</dl>
<dl>
<dt><img src="images/product07.png" alt=""></dt>
<dd>
<p>现代北欧风格厨房装</p>
<p>2029饰效果图</p>
</dd>
</dl>
<dl>
<dt><img src="images/product08.png" alt=""></dt>
<dd>
<p>现代时尚北欧风格卧</p>
<p>2029室装饰画</p>
</dd>
</dl>
<dl>
<dt><img src="images/product09.png" alt=""></dt>
<dd>
<p>130平简约现代北欧</p>
<p>2029风格装修</p>
</dd>
</dl>
<dl>
<dt><img src="images/product10.png" alt=""></dt>
<dd>
<p>现代北欧风格小客厅</p>
<p>2029装修设计</p>
</dd>
</dl>
</div>
</div>
</section>
<!-- 了解我们区域 -->
<section class="aboutusbar center-wrap">
<!-- 上半部分 -->
<div class="aboutus-top">
<div class="title">
<div class="line"></div>
<div class="text">
<h3>了解我们</h3>
<p>about us</p>
<div class="title_line"></div>
</div>
</div>
</div>
<!-- 下半部分 -->
<div class="aboutus-bottom">
<div class="bottom_left">
<div class="title">
<h4>关于我们</h4>
<p>慕家居装饰材料有限公司</p>
<div class="title_line"></div>
</div>
<div class="text">
<p>慕家居家居装修网北欧风格家
具图片专区,是国内海量全面的
高质量北欧风格家具图片库…</p>
</div>
<div class="more">
<a href="">了解更多</a>
</div>
</div>
<div class="bottom_middle">
<img src="images/aboutus.png" alt="">
</div>
<div class="bottom_right">
<div class="box1 box">
<div class="message text">
<div class="p1">在线留言</div>
<div class="p2">on-line message</div>
</div>
</div>
<div class="box2 box">
<div class="ad text">
<div class="p1">广告经营</div>
<div class="p2">Advertising management</div>
</div>
</div>
<div class="box3 box">
<div class="web text">
<div class="p1">网络咨询</div>
<div class="p2">Network consultation</div>
</div>
</div>
</div>
</div>
</section>
<!-- 精品推荐区域 -->
<section class="goodsbar center-wrap">
<!-- 上半部分 -->
<div class="goods-top">
<div class="text">
<h3>精品推荐</h3>
<p>Boutique recommendation</p>
<div class="title_line"></div>
</div>
</div>
<!-- 下半部分 -->
<div class="goods-bottom center-wrap">
<div class="leftbtn"><a href=""></a></div>
<div class="rightbtn"><a href=""></a></div>
<div class="goods">
<dl>
<dt><img src="images/recommend1.png" alt=""></dt>
<dd>
<p>轻奢风格样板房客厅色彩搭配装修设计</p>
</dd>
</dl>
<dl>
<dt><img src="images/recommend2.png" alt=""></dt>
<dd>
<p>简约美式风格卧室衣柜设计</p>
</dd>
</dl>
<dl>
<dt><img src="images/recommend3.png" alt=""></dt>
<dd>
<p>轻奢风格L型厨房装修设计</p>
</dd>
</dl>
</div>
</div>
<!-- 新闻中心区域 -->
</section>
<!-- 新闻中心区域 -->
<section class="newsbar center-wrap">
<!-- 上半部分 -->
<div class="news-top">
<div class="title">
<div class="line"></div>
<div class="text">
<h3>新闻中心</h3>
<p>press center</p>
<div class="title_line"></div>
</div>
</div>
</div>
<!-- 下半部分 -->
<div class="news-bottom">
<div class="content">
<ol>
<li class="list1 list">
<div class="no1 no">01</div>
<dl>
<dt>最新招标</dt>
<dd>重庆业主要求:一居室的户型,想把阳台利用起来,改成一室一厅的户型,业主表示已经请朋友把以前的装修敲了,现在基本是毛坯的状态……</dd>
</dl>
</li>
<li class="list2 list">
<div class="no2 no">02</div>
<dl>
<dt>装修日记</dt>
<dd>终于在北京四环里贷款买了套两居室二手房,还是很欣喜的,为了装好它,我可真是费了心了,毕竟是自己以后的小家,所以我真是没少操心……</dd>
</dl>
</li>
<li class="list3 list">
<div class="no3 no">03</div>
<dl>
<dt>装修百科</dt>
<dd>买房之后,无论是毛坯房还是留下二手房,很多业主都会选择进行装修。装修可以为你带来一个你喜欢的房屋,同时满足你需要的生活方式……</dd>
</dl>
</li>
<li class="list4 list">
<div class="no4 no">04</div>
<dl>
<dt>热门搜索</dt>
<dd>选择防盗门最重要的就是工艺质量:应特别注意检查有无焊接缺陷,诸如开焊、未焊、漏焊等现象。看门扇与门框的配合是否密实,间隙是否均匀……</dd>
</dl>
</li>
</ol>
</div>
</div>
</section>
<!-- footer区域 -->
<footer class="footerbar">
<div class="center-wrap">
<div class="contact">
<div class="logo">
<p>慕家居</p>
</div>
<div class="message">
<p>咨询电话:010-88888888</p>
<p>公司网址:www.imooc.com</p>
<p>邮箱:KEFU@IMOOC.com</p>
</div>
</div>
</div>
<div class="copyright">
<p>Copyright © 2020 imooc.com All Rights Reserved | 京ICP备 </p>
</div>
</footer>
</body>
</html>
相关代码:CSS
*{
margin: 0;
padding: 0;
}
/* top区域 */
.topbar{
width: 100%;
height: 40px;
background-color: #0058AA;
}
.topbar .center-wrap p{
float:right;
font-size: 18px;
color: #FFFFFF;
line-height: 40px;
padding-right: 15px;
}
/* head区域 */
/* logo所在的盒子 */
.headbar{
overflow: hidden;
width: 100%;
height: 121px;
}
.headbar .center-wrap .logo{
float: left;
width: 302px;
height: 121px;
cursor:pointer;
}
.headbar .center-wrap .logo p{
font-size: 64px;
color: #0058AA;
line-height: 121px;
}
/* headnav盒子 */
.headbar .center-wrap .headnav{
float: left;
width: 543px;
height: 121px;
padding-left: 30px;
}
.headbar .center-wrap .headnav .headpic ul li {
float: left;
margin-right: 40px;
}
.headbar .center-wrap .headnav .headpic ul li a{
text-decoration: none;
display: block;
width: 29px;
height: 28px;
text-align: center;
line-height: 30px;
font-size: 30px;
border-radius: 50%;
margin: 20px auto;
color: gray;
}
/* 呼吸效果 */
@keyframes pulse{
from{
transform: scale(1);
}
to {
transform: scale(1.08);
}
}
.headbar .center-wrap .headnav .headpic ul li:hover a{
animation: pulse 0.5s infinite alternate;
background-color: #0058AA;
color: white;
}
/* .soso-box */
.headbar .center-wrap .soso-box{
float: left;
width: 325px;
padding-top: 37px;
}
.headbar .center-wrap .soso-box input{
float: left;
left: 50px;
width: 273px;
height: 37px;
border: 1px solid #D3D3D3;
border-radius: 3px 0 0 3px;
outline: none;
}
.headbar .center-wrap .soso-box input::-webkit-input-placeholder{
padding-left: 15px;
font-size: 14px;
color: #545454;
}
.headbar .center-wrap .soso-box .btn{
float: right;
width: 50px;
height: 39px;
text-align: center;
line-height: 39px;
background-color: #0058AA;
font-size: 34px;
color: white;
}
/* banner区域 */
.bannerbar{
width: 100%;
height: 495px;
position: relative;
}
.bannerbar .banner{
height: 496px;
position: relative;
}
.bannerbar .banner img{
width: 100%;
position: absolute;
left: 0;
top: 0;
display: none;
}
/* 有active类名的 图片是显示的 */
.bannerbar .banner img.active {
display: block;
}
.bannerbar .circles{
width: 130px;
height: 25px;
text-align: center;
position: absolute;
bottom: 20px;
left: 50%;
margin-left: -65px;
}
.bannerbar .circles span{
display: inline-block;
width: 20px;
height: 20px;
border-radius: 50%;
background: #ccc;
margin: 10px;
}
/* 当前小点(对应图片的小点)的样式 */
.bannerbar .circle span.active{
background-color: blue;
}
/* 商品区域 */
.productsbar{
position: relative;
overflow: hidden;
height: 252px;
margin-top: 35px;
}
.productsbar .leftbtn a{
display: block;
float: left;
width: 48px;
height: 48px;
position: absolute;
top: 50%;
margin-top: -24px;
background:url(../images/prev.png);
}
.productsbar .leftbtn a:hover{
background: url(../images/prev_active.png);
}
.productsbar .rightbtn a{
display: block;
float:right;
width: 48px;
height: 48px;
position: absolute;
right: 0;
top: 50%;
margin-top: -24px;
background: url(../images/next.png);
}
.productsbar .rightbtn a:hover{
background: url(../images/next_active.png);
}
.productsbar .products{
width: 1095px;
margin:0 auto;
overflow: hidden;
}
/* 宽度设置足够大,让dl全部显示在一行 */
.productsbar .products .products_box{
width: 6000px;
}
.productsbar .products dl{
float: left;
margin: 24px;
}
.productsbar .products dl dt{
width: 171px;
height: 175px;
}
.productsbar .products dl dd p{
font-size: 15px;
color: #838383;
text-align: left;
}
/* 了解我们区域 */
.aboutusbar{
width: 1155px;
margin: 30px auto 0;
}
/* 上半部分 */
.aboutusbar .aboutus-top{
height: 70px;
margin: 20px 0;
position: relative;
}
/* 设置横线的样式 */
.aboutusbar .aboutus-top .line {
width: 100%;
height: 1px;
background: #9B9B9B;
position: absolute;
top: 50%;
}
.aboutusbar .aboutus-top .text {
width: 155px;
background-color: white;
position: absolute;
top: 0;
left: 50%;
margin-left: -77.5px;
text-align: center;
}
.aboutusbar .aboutus-top .text h3 {
font-size: 32px;
color: #696868;
font-weight: normal;
}
.aboutusbar .aboutus-top .text p {
font-size: 18px;
color: #9B9B9B;
}
/* 设置标题下的蓝色横线样式 */
.aboutusbar .aboutus-top .title_line {
width: 93px;
height: 3px;
background: #0058AA;
display: inline-block;
}
/* 下半部分 */
.aboutusbar .aboutus-bottom{
height: 300px;
overflow: hidden;
}
/* 左边盒子 */
.aboutusbar .aboutus-bottom .bottom_left{
width: 240px;
float: left;
}
.aboutusbar .aboutus-bottom .bottom_left .title h4{
font-size: 26px;
color: #0058AA;
}
.aboutusbar .aboutus-bottom .bottom_left .title p{
font-size: 21px;
color: #5A5A5A;
line-height: 41px;
}
.aboutusbar .aboutus-bottom .bottom_left .title .title_line{
width: 142px;
height: 4px;
background: #0058AA;
display: inline-block;
text-align: center;
}
.aboutusbar .aboutus-bottom .bottom_left .text{
width: 240px;
height: 78px;
margin-top: 10px;
font-size: 18px;
color: #7B7C7C;
line-height: 26px;
}
.aboutusbar .aboutus-bottom .bottom_left .more a{
text-decoration: none;
font-size: 18px;
color: #FFFFFF;
text-align: right;
width: 130px;
height: 38px;
display: inline-block;
background-color: #0058AA;
text-align: center;
line-height: 38px;
margin-top: 27px;
}
/* 鼠标移入时调用动画 */
.aboutusbar .aboutus-bottom .bottom_left .more:hover a{
-webkit-animation: swing 1s infinite;
}
/* 定义动画 */
@-webkit-keyframes swing{
0%{
transform :rotate(9deg);
}
50%{
transform: rotate(-9deg);
}
100%{
transform: rotate(9deg);
}
}
/* 中间盒子 */
.aboutusbar .aboutus-bottom .bottom_middle{
width: 384px;
height: 256px;
float: left;
margin-left: 140px;
margin-right: 110px;
overflow: hidden;
}
.aboutusbar .aboutus-bottom .bottom_middle img{
transition: transform 2s ease-out 0s;
}
.aboutusbar .aboutus-bottom .bottom_middle:hover img{
transform: scale(1.1);
}
/* 右边盒子 */
.aboutusbar .aboutus-bottom .bottom_right{
width: 273px;
float: right;
}
.aboutusbar .aboutus-bottom .bottom_right .box{
width: 273px;
height: 61px;
background: #CCCCCC;
margin-top: 10px;
color: white;
overflow: hidden;
transition: background-color 0.5s;
}
.aboutusbar .aboutus-bottom .bottom_right .box:hover{
background-color: #0058AA;
}
.aboutusbar .aboutus-bottom .bottom_right .box .text{
width: 183px;
height: 50px;
padding: 11px 0 5px 89px;
position: relative;
}
.aboutusbar .aboutus-bottom .bottom_right .box .message::before,
.aboutusbar .aboutus-bottom .bottom_right .box .ad::before,
.aboutusbar .aboutus-bottom .bottom_right .box .web::before{
content: "";
float: left;
display: block;
width: 40px;
height: 34px;
position: absolute;
left: 30px;
top: 14px;
}
.aboutusbar .aboutus-bottom .bottom_right .box .message::before{
background-image: url(../images/liuyan.png);
}
.aboutusbar .aboutus-bottom .bottom_right .box .ad::before{
background-image: url(../images/guanggao.png);
}
.aboutusbar .aboutus-bottom .bottom_right .box .web::before{
background-image: url(../images/wangluo.png);
}
.aboutusbar .aboutus-bottom .bottom_right .box .p1{
font-size: 16px;
display: block;
width: 88px;
height: 29px;
text-align: center;
bottom: 0;
}
.aboutusbar .aboutus-bottom .bottom_right .box .p2{
font-size: 8px;
left: 50px;
text-align: left;
}
/* 精品推荐区域 */
.goodsbar{
width: 100%;
height: 480px;
background: #EFF0F4;
}
.goodsbar .goods-top{
height: 100px;
position: relative;
}
.goodsbar .goods-top .text{
width: 232px;
position: absolute;
top: 0;
left: 50%;
margin-left: -116px;
text-align: center;
padding-top: 50px;
}
.goodsbar .goods-top .text .title_line{
width: 93px;
height: 3px;
background: #0058AA;
display: inline-block;
}
.goodsbar .goods-top .text h3 {
font-size: 32px;
color: #696868;
font-weight: normal;
}
.goodsbar .goods-top .text p {
font-size: 18px;
color: #9B9B9B;
}
/* 下半部分 */
.goodsbar .goods-bottom{
position: relative;
overflow: hidden;
}
.goodsbar .goods-bottom .leftbtn a{
display: block;
float: left;
width: 48px;
height: 48px;
position: absolute;
top: 50%;
margin-top: -24px;
background:url(../images/prev.png);
}
.goodsbar .goods-bottom .leftbtn a:hover{
background: url(../images/prev_active.png);
}
.goodsbar .goods-bottom .rightbtn a{
display: block;
float:right;
width: 48px;
height: 48px;
position: absolute;
right: 0;
top: 50%;
margin-top: -24px;
background: url(../images/next.png);
}
.goodsbar .goods-bottom .rightbtn a:hover{
background: url(../images/next_active.png);
}
.goodsbar .goods-bottom .goods{
height: 330px;
width: 1075px;
margin: 25px auto 0;
}
.goodsbar .goods-bottom .goods dl{
float: left;
width: 345px;
height: 326px;
margin-left: 10px;
}
.goodsbar .goods-bottom .goods dl dt img{
vertical-align: middle;
}
.goodsbar .goods-bottom .goods dl dd{
display: block;
width: 345px;
height: 45px;
position: absolute;
bottom: 0px;
background: rgba(0,0,0,0.50);
text-align: center;
line-height: 45px;
}
.goodsbar .goods-bottom .goods dl dd p{
font-size: 16px;
color: #FFFFFF;
text-align: right;
position: absolute;
left: 20px;
}
/* 新闻中心区域 */
.newsbar{
width: 1155px;
margin: 30px auto 0;
overflow: hidden;
}
/* 上半部分 */
.newsbar .news-top{
height: 70px;
margin: 20px 0;
position: relative;
}
/* 设置横线的样式 */
.newsbar .news-top .line {
width: 100%;
height: 1px;
background: #9B9B9B;
position: absolute;
top: 50%;
}
.newsbar .news-top .text {
width: 155px;
background-color: white;
position: absolute;
top: 0;
left: 50%;
margin-left: -77.5px;
text-align: center;
}
.newsbar .news-top .text h3 {
font-size: 32px;
color: #696868;
font-weight: normal;
}
.newsbar .news-top .text p {
font-size: 18px;
color: #9B9B9B;
}
/* 设置标题下的蓝色横线样式 */
.newsbar .news-top .title_line {
width: 93px;
height: 3px;
background: #0058AA;
display: inline-block;
}
/* 下半部分 */
.newsbar .news-bottom .content{
width: 1155px;
height: 270px;
border-color: bisque;
margin-bottom: 50px;
overflow: hidden;
}
.newsbar .news-bottom .content ol > li{
float: left;
width: 503px;
height: 112px;
margin-left: 38px;
margin-top: 26px;
}
.newsbar .news-bottom .content ol > li dl{
width: 400px;
height: 112px;
float: right;
}
.newsbar .news-bottom .content ol > li dl dt{
display: inline-block;
font-size: 19px;
color: #4A4A4A;
text-align: right;
margin-bottom: 10px;
margin-top: 10px;
}
.newsbar .news-bottom .content ol > li dd{
display: inline-block;
font-size: 15px;
color: #4A4A4A;
}
.newsbar .news-bottom .content ol > li > div{
float: left;
width: 65px;
height: 65px;
font-size: 40px;
color: white;
text-align: center;
background: url(../images/talk-bg.png);
}
.newsbar .news-bottom .content ol > li > div:hover{
animation: move 1s linear 0s infinite;
}
@-webkit-keyframes move{
0%{
margin-top: 5px;
}
50%{
margin-top: 0px;
}
100%{
margin-top: 10px;
}
}
/* footer区域 */
.footerbar{
overflow: hidden;
width: 100%;
background: #06142F;
}
.footerbar .center-wrap{
height: 210px;
}
.footerbar .center-wrap .contact{
height: 210px;
}
.footerbar .center-wrap .contact .logo{
}
.footerbar .center-wrap .contact .logo p{
float: left;
font-size: 48px;
color: #FFFFFF;
line-height: 210px;
}
.footerbar .center-wrap .contact .message{
float: left;
margin-left: 100px;
margin-top: 35px;
}
.footerbar .center-wrap .contact .message p{
font-size: 16px;
color: #FFFFFF;
line-height: 40px;
}
.footerbar .copyright{
background: #202C46;
height: 30px;
font-size: 14px;
color: #FFFFFF;
text-align: center;
line-height: 30px;
}
相关代码:base.css
body{
font-family: "微软雅黑";
}
@font-face {
font-family: 'iconfont';
src: url('../fonts/iconfont.ttf') format('truetype');
}
.iconfont {
font-family: "iconfont" !important;
font-size: 16px;
font-style: normal;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
.center-wrap {
width: 1200px;
margin: 0 auto;
}
.clearfix {
overflow: hidden;
}
.clearfix::after {
content: '';
display: block;
clear: both;
overflow: hidden;
}
相关代码:js
(function(){
//得到元素
var products =document.getElementById('products');
var left_btn=document.getElementById('left_btn');
var right_btn=document.getElementById('right_btn');
//右按钮设置监听
right_btn.onclick=function(){
}
})();
1回答
好帮手慕然然
2021-06-18
同学你好,商品区域的轮播图是通过点击左右切换按钮来实现的:每点击一次,轮播图盒子就会移动一个轮播图列表的距离,所以,关键是要理解点击次数与轮播图盒子移动的距离之间是如何变化和计算的,如图

根据以上原理,使用代码实现:


祝学习愉快!
相似问题