让旋转木马停止
我有一个带有三个 元素的轮播。像这样:
<div role="main" class="main selection-carousel">
<section>
<h1>Kies je <span class="right">favoriete</span> Smaak</h1>
<aside class="aside">
</aside>
</section>
<section>
<h1>Item 2</h1>
<aside class="aside">
</aside>
</section>
<section>
<h1>Item 3</h1>
<aside class="aside">
</aside>
</section>
<img src="static/img/bg-selection-carousel.png" width="2610" height="600" alt="" class="carousel-image">
<a href="#" title="Ga naar de volgende thee smaak" class="carousel-left">Ga naar de volgende thee smaak</a>
<a href="#" title="Ga naar de vorige thee smaak" class="carousel-right">Ga naar de vorige thee smaak</a>
</div>
当您单击 .carousel-left 时。
向左移动 -1000 像素。第二部分是表演。当您点击右侧的轮播时。图像向右移动 1000 像素。前面的部分是显示的。
但我的轮播按钮有问题。当我在第一部分时。那么就不能右键轮播了。我怎样才能做到这一点?
当我在第一部分的时候。应该把轮播右键隐藏起来。当我进入最后一部分时。左边的旋转木马应该被隐藏。
谢谢!
这是我的 JavaScript:
$(function () {
var background = $(".carousel-image")
buttonLeft = $(".carousel-left")
buttonRight = $(".carousel-right");
$("section").hide();
$("section:first").show();
buttonLeft.click(function (e) {
e.preventDefault();
background.animate({ left: "-=1000px" }, 1100, "easeOutQuad", function () {
$("section:visible").hide().next().fadeIn(600);
});
});
buttonRight.click(function (e) {
e.preventDefault();
background.animate({ left: "+=1000px" }, 1100, "easeOutQuad", function () {
$("section:visible").hide().prev().fadeIn(600);
});
});
});
I have a carousel with three <section>
elements. Like this:
<div role="main" class="main selection-carousel">
<section>
<h1>Kies je <span class="right">favoriete</span> Smaak</h1>
<aside class="aside">
</aside>
</section>
<section>
<h1>Item 2</h1>
<aside class="aside">
</aside>
</section>
<section>
<h1>Item 3</h1>
<aside class="aside">
</aside>
</section>
<img src="static/img/bg-selection-carousel.png" width="2610" height="600" alt="" class="carousel-image">
<a href="#" title="Ga naar de volgende thee smaak" class="carousel-left">Ga naar de volgende thee smaak</a>
<a href="#" title="Ga naar de vorige thee smaak" class="carousel-right">Ga naar de vorige thee smaak</a>
</div>
When you click on the <a>
.carousel-left. The <img>
go -1000 pixels to the left. And the second section is show. When you click on carousel-right. The image go 1000 pixels to right. And the section before is show.
But i have a problem with the carousel buttons. When i am on the first section. Then you can not right-click carousel. How can i make that?
When I am in the first section. Should the carousel right-button hidden. And when I'm in the last section. Left the carousel should be hidden.
Thanks!
This is my javascript:
$(function () {
var background = $(".carousel-image")
buttonLeft = $(".carousel-left")
buttonRight = $(".carousel-right");
$("section").hide();
$("section:first").show();
buttonLeft.click(function (e) {
e.preventDefault();
background.animate({ left: "-=1000px" }, 1100, "easeOutQuad", function () {
$("section:visible").hide().next().fadeIn(600);
});
});
buttonRight.click(function (e) {
e.preventDefault();
background.animate({ left: "+=1000px" }, 1100, "easeOutQuad", function () {
$("section:visible").hide().prev().fadeIn(600);
});
});
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在这里做了一个类似的轮播: http://jsbin.com/abape3/14
如果你替换将我的示例中的
input
与您的section
进行稍微调整,您应该能够使其工作。I've done a similar carousel here: http://jsbin.com/abape3/14
If you replace the
input
's in my example with yoursection
's and tweak it slightly you should be able to make it work.