Django打造大型企业官网(四)
程序员文章站
2022-04-10 22:04:47
4.3.轮播图布局和样式 templates/news/index.html src/css/index.scss 4.4.实现一次轮播 templates/news/index.html src/js/index.js 4.5.实现自动轮播 src/js/index.js ......
4.3.轮播图布局和样式
templates/news/index.html
<div class="news-wrapper"> <div class="banner-group"> <ul class="banner-ul"> <li> <a href=""> <img src="https://static-image.xfz.cn/1523588994_243.jpg" alt=""> </a> </li> <li> <a href=""> <img src="https://static-image.xfz.cn/1521444982_469.jpg" alt=""> </a> </li> <li> <a href=""> <img src="https://static-image.xfz.cn/1521444982_469.jpg" alt=""> </a> </li> <li> <a href=""> <img src="https://static-image.xfz.cn/1523588994_243.jpg" alt=""> </a> </li> </ul> </div> </div>
src/css/index.scss
.news-wrapper{ float: left; width: 798px; height: 500px; background: #fff; .banner-group{ width: 100%; height: 202px; background: #0a275a; .banner-ul{ overflow: hidden; width: 798px * 4; li{ float: left; width: 798px; height: 202px; img{ width: 798px; height: 202px; } } } } } .sidebar-wrapper{ float: right; width: 356px; height: 500px; background: darkseagreen; } } }
4.4.实现一次轮播
templates/news/index.html
<script src="../../dist/js/jquery-3.3.1.min.js" ></script> <script src="../../dist/js/index.min.js" ></script> <ul class="banner-ul" id="banner-ul">
src/js/index.js
//初始化 function banner() { }; //添加一个run方法 banner.prototype.run = function () { var bannerul = $("#banner-ul"); //500是间隔时间0.5s bannerul.animate({"left":-798},500) }; //页面加载完成后执行。创建一个对象,运行方法 $(function () { var banner = new banner(); banner.run() });
4.5.实现自动轮播
src/js/index.js
//添加一个run方法 banner.prototype.run = function () { var bannerul = $("#banner-ul"); var index = 0; setinterval(function () { if(index >= 3){ index = 0 }else{ index++; } bannerul.animate({"left":-798*index},500); },2000); };