서로다른 이미지 깜박이며 노출
HTML
<div id="wrap">
<div class="fade_container">
<img class="active" src="http://sevensprings.dothome.co.kr/img/4.jpg" alt="image1" />
<img src="http://sevensprings.dothome.co.kr/img/5.jpg" alt="image2" />
<img src="http://sevensprings.dothome.co.kr/img/6.jpg" alt="image3" />
</div>
</div>
CSS
body {
background-color:#111;
}
#wrap{
margin:30px auto;
width:600px;
}
.fade_container {
position:relative;
width:600px;
height:350px;
border:2px solid gold;
}
.fade_container img{
position:absolute;
width:100%;
height:100%;
}
.fade_container img:nth-child(1){
background-color:#fff;
}
.fade_container img:nth-child(2){
background-color:red;
}
.fade_container img:nth-child(3){
background-color:blue;
}
.fade_container .active{
z-index:1;
}
JS
var now_img, next_img;
function fade_change(){
now_img = $(".fade_container img:eq(0)");
next_img = $(".fade_container img:eq(1)");
next_img.addClass("active").css("opacity",0).animate({"opacity":1},1000, function(){
$(".fade_container").append(now_img); //콜백
now_img.removeClass("active");
});
}
/*
fade_change() 함수를 순환시키는 timer 설정
mouse hover 로 애니메이션 멈춤/재생
*/
var timer = setInterval("fade_change()",4000);
$("div.fade_container").hover(function(){ // mouse enter
clearInterval(timer);
}, function(){ // mouse leave
timer = setInterval("fade_change()",4000);
});
코드적용
'작업 일지 > JS' 카테고리의 다른 글
하드코딩 chart(js) / 그라데이션(css) (0) | 2024.03.14 |
---|---|
length > 0 해당 요소가 있을경우 (0) | 2024.03.05 |
이미지 사이즈에 맞게 팝업 띄우기 (0) | 2024.03.04 |
iframe 스크롤 없애기 (0) | 2023.07.05 |
따라다니는 배너 (0) | 2023.07.05 |