javascript/jqueryを初めて使用しました。イメージスライダを構築しています。画像をアニメーション化するようなことはできません。私はここで何が間違っているのか分からない。jqueryの画像スライダをアニメーション化できません
私がやっていることは、アクティブなスライドを取得して次の兄弟をスライドさせてアニメーション化することですが、結果として得られるのは、最初のイメージがアニメーション化して停止することです。ここで
はコードです:https://jsfiddle.net/6qntgg5z/
<div id="container">
<header>
header is here
</header>
<div id="carousel">
<div class="sliderbuttons">
<input type="button" name="next" id="next" value=" > ">
<input type="button" name="next" id="prev" value=" < ">
</div>
<div class="slides">
<img src="http://www.planwallpaper.com/static/images/4-Nature-Wallpapers-2014-1_ukaavUI.jpg" alt="image1" class="slide active">
<img src="http://www.mrwallpaper.com/wallpapers/green-Rice-1600x900.jpg" alt="image2" class="slide">
<img src="http://cdn.wonderfulengineering.com/wp-content/uploads/2016/01/nature-wallpapers-10.jpg" alt="image3" class="slide">
</div>
</div>
</div>
CSS
html,body {
height: 100%;
position: relative;
}
*{
box-sizing: border-box;
}
#container {
width: 90%;
margin: 0 auto;
height: 100%;
}
header {
background: black;
height: 20px;
padding: 1.5em;
color: white;
}
#carousel {
position: relative;
margin: 0 auto;
width: 45%;
margin-top: 15px;
height: 100%;
}
.slide {
position: absolute;
max-width: 100%;
z-index: 0;
}
.sliderbuttons {
}
#prev,#next {
position: absolute;
background-color: rgba(255, 148, 41, 0.68);
box-shadow: 2px white;
border:none;
font-size: 2em;
color: white;
font-weight: bold;
/* font-family: 'Baloo Tamma', cursive;
*/ padding:10px;
top:15%;
width: 10%;
/*making the prev,next on top of content*/
z-index: 2;
}
#prev {
left:0;
}
#next {
right:0;
}
.active {
z-index: 1;
}
Javascriptを
$(document).ready(function(){
setInterval(animateSlider(), 5000);
});
//configuration
var currentSlide=activeSlide();
var slides=$("#carousel .slides .slide");
//get active slide index
function activeSlide(){
var activeSlide=$("#carousel .slides .active").index();
return activeSlide;
}
function animateSlider() {
var $current=slides.eq(activeSlide());
var $next= $(".slides img:first");
$next.addClass('active');
$current.animate({opacity: 0.0}, 1000,
function() {
$current.removeClass('active');
$current.css({opacity: 1.0});
});
インデックスと.slides長との間に矛盾があるようだ、私は、その問題上の任意の提案を作業する方法がわかりませんか? – Ndx
私は自分のバージョンのものを見つけて設計しようとするあなたのアプローチを続けるべきだと思います!あなたは時間のクランチをしているので、これは非常に便利です。 –
私は画像スライダのカップルを知っていますが、他のスライダをチェックアウトする前にまずjqueryに慣れ親しんで、それらがどのようにコード化されているかを調べています。ありがとう、私はそれを見てみましょう。 – Ndx