-
글쓴이글
-
2021년 10월 4일 03:02 #16014
김인환참가자http://sdcode.dothome.co.kr/sd-main-page/index.html
이미지 나타내는 기능 만들고 있는데
코드가 너무 비효율적입니다.. 도와주세여 ㅠㅠ
function headerFade(){
$('.header-img-1').css('opacity', 1);
$('.header-img-2').css('opacity', 0);
$('.header-img-3').css('opacity', 0);
$('.header-img-4').css('opacity', 0);
}
headerFade();setTimeout(function(){
function headerFade2(){
$('.header-img-1').css('opacity', 0);
$('.header-img-2').css('opacity', 1);
$('.header-img-3').css('opacity', 0);
$('.header-img-4').css('opacity', 0);
}
headerFade2();
},4000);setTimeout(function(){
function headerFade3(){
$('.header-img-1').css('opacity', 0);
$('.header-img-2').css('opacity', 0);
$('.header-img-3').css('opacity', 1);
$('.header-img-4').css('opacity', 0);
}
headerFade3();
},8000);setTimeout(function(){
function headerFade4(){
$('.header-img-1').css('opacity', 0);
$('.header-img-2').css('opacity', 0);
$('.header-img-3').css('opacity', 0);
$('.header-img-4').css('opacity', 1);
}
headerFade4();
},12000);setInterval(()=> {
function headerFade(){
$('.header-img-1').css('opacity', 1);
$('.header-img-2').css('opacity', 0);
$('.header-img-3').css('opacity', 0);
$('.header-img-4').css('opacity', 0);
}
headerFade();setTimeout(function(){
function headerFade2(){
$('.header-img-1').css('opacity', 0);
$('.header-img-2').css('opacity', 1);
$('.header-img-3').css('opacity', 0);
$('.header-img-4').css('opacity', 0);
}
headerFade2();
},4000);setTimeout(function(){
function headerFade3(){
$('.header-img-1').css('opacity', 0);
$('.header-img-2').css('opacity', 0);
$('.header-img-3').css('opacity', 1);
$('.header-img-4').css('opacity', 0);
}
headerFade3();
},8000);setTimeout(function(){
function headerFade4(){
$('.header-img-1').css('opacity', 0);
$('.header-img-2').css('opacity', 0);
$('.header-img-3').css('opacity', 0);
$('.header-img-4').css('opacity', 1);
}
headerFade4();
},12000);
}, 16000);어떻게 짜야지 효율적으로 만들 수 있을까요..?
2021년 10월 4일 09:42 #16032
codingapple키 마스터함수들이 다 비슷하게 생겼을 땐
파라미터 뚫어놓으면 비슷한 함수 여러개 만들 필요 없습니다
function headerFade(aaa){
$('.header-img-1').css('opacity', 0);
$('.header-img-2').css('opacity', 0);
$('.header-img-3').css('opacity', 0);
$('.header-img-4').css('opacity', 0);
$('.header-img-' + aaa).css('opacity', 1);}
이렇게 만들어두면 headerFade(1) 이러면 .header-img-1 만 보이겠네요
-
글쓴이글
- 답변은 로그인 후 가능합니다.