【发布时间】:2016-05-10 06:32:00
【问题描述】:
我正在通过纯 JavaScript 实现轮播(不使用插件)。我想设置上一个和下一个按钮来控制幻灯片图像。
var firstval = 0;
function Carousel() {
firstval += 2;
parent = document.getElementById('container-carousel');
parent.style.left = "-" + firstval + "px";
if (!(firstval % 150)) {
setTimeout(Carousel, 3000);
firstval = 0;
var firstChild = parent.firstElementChild;
parent.appendChild(firstChild);
parent.style.left= 0;
return;
}
runCarousel = setTimeout(Carousel, 10);
}
Carousel();
#wrapper-carousel {
position: relative;
width: 450px;
height: 150px;
margin: 0 auto;
overflow: hidden;
}
#container-carousel {
position: absolute;
width: 450px;
height: 150px;
}
.child {
width: 150px;
height: 150px;
padding-top: 35px;
float: left;
text-align: center;
font-size: 60px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.2.3/jquery.min.js"></script>
<div id="wrapper-carousel">
<div id="container-carousel">
<div class="child"><img width="100" src="https://d2z4fd79oscvvx.cloudfront.net/0020232_chocolate_cream_gateaux_cake_320.jpeg"> </div>
<div class="child"><img width="100" src="https://d2z4fd79oscvvx.cloudfront.net/0018904_50_red_roses_in_vase_320.jpeg"> </div>
<div class="child"><img width="100" src="https://d2z4fd79oscvvx.cloudfront.net/0020232_chocolate_cream_gateaux_cake_320.jpeg"> </div>
</div>
<a class="left" href="#wrapper-carousel" style="font-size:100px;z-index:3000;">‹</a>
<a class="right" href="#wrapper-carousel" style="font-size:100px;z-index:3000">›</a>
</div>
我想添加一个简单的按钮来控制这个轮播。我没有使用任何插件和任何框架轮播。
【问题讨论】:
-
你能说清楚你的问题吗?你想做css或功能
-
你有试过左右点击的任何东西吗?
-
@ketan。我试过 href="#wrapper-carousel " ,
-
@varunsharma 你可以在这里继续前进。jsfiddle.net/wzkLjh8s/24
标签: javascript jquery html css