저는 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;
}
자바 스크립트
$(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
나는 이것의 자신의 버전을 알아 내고 디자인하려고 노력하는 당신의 접근을 계속해야한다고 생각한다! 그러나 unslider는 이것을 위해 매우 편리합니다. 당신은 시간 위기에 처해 있습니다. –
이미지 슬라이더 몇 개를 알고 있지만 다른 슬라이더를 확인하기 전에 jquery에 익숙해지기 위해 노력하고 있습니다. 고마워, 나는 그것을 볼 것이다. – Ndx