2016-09-12 19 views
0

안녕하세요 jQuery 이미지 crossfade 설정에 문제가 있습니까? http://tips.techmatemn.com/jQuery Image Crossfade가 작동하지 않습니다.

HTML

<div class="hero-cycler"> 
    <img class="active" alt="Tips qualified Client 1" src="<?php bloginfo('stylesheet_directory'); ?>/assets/img/hero-bk-1.jpg"> 
    <img alt="Tips qualified Client 2" src="<?php bloginfo('stylesheet_directory'); ?>/assets/img/hero-bk-2.jpg"> 
</div> 

CSS

.hero-cycler{position:relative;} 
.hero-cycler img{position:absolute;z-index:1} 
.hero-cycler img.active{z-index:3} 

SCRIPT

<script> // homepage client images 
function cycleImages(){ 
     var $active = $('.hero-cycler .active'); 
     var $next = ($active.next().length > 0) ? $active.next() : $('.hero-cycler img:first'); 
     $next.css('z-index',2);//move the next image up the pile 
     $active.fadeOut(1500,function(){//fade out the top image 
     $active.css('z-index',1).show().removeClass('active');//reset the z-index and unhide the image 
      $next.css('z-index',3).addClass('active');//make the next image the top one 
     }); 
    } 

$(document).ready(function(){ 
// run every 7s 
setInterval('cycleImages()', 7000); 
}) 
</script> 

감사합니다!

+0

뭐가 보이니? 정확히 작동하지 않는 것은 무엇입니까? 어떤 오류가 있습니까? 또한 두 이미지 사이를 순환하는 경우이 작업을 크게 단순화 할 수 있습니다. – DBS

+0

일단 우리가이 작업을하면 더 많은 이미지를 갖게 될 것입니다. 나는 첫 번째 이미지를 본다. 내 생각 엔 이미지가 순환되지 않기 때문에 스크립트가 작동하지 않는 것입니다. – angeladesign

+0

브라우저 콘솔에서 오류를 확인하십시오. 항상 시작하는 것이 좋습니다. 나는 이것을 바이올린에 집어 넣고 무슨 일이 일어나는지 보게 될 것이다. – DBS

답변

0

함수 호출 방식을 변경하십시오. setInterval은 감가 상각되는 문자열 매개 변수를 사용하며 일반적으로 권장되지 않습니다. 아래 표시된 표준 방법을 사용하여 기능을 올바르게 실행하십시오.

변경 setInterval('cycleImages()', 7000); 일반적인 필러 이미지 setInterval(cycleImages, 7000);

전체 작업 사본 :

function cycleImages() { 
 
    var $active = $('.hero-cycler .active'); 
 
    var $next = ($active.next().length > 0) ? $active.next() : $('.hero-cycler img:first'); 
 
    $next.css('z-index', 2); //move the next image up the pile 
 
    $active.fadeOut(1500, function() { //fade out the top image 
 
    $active.css('z-index', 1).show().removeClass('active'); //reset the z-index and unhide the image 
 
    $next.css('z-index', 3).addClass('active'); //make the next image the top one 
 
    }); 
 
} 
 

 
$(document).ready(function() { 
 
    // run every 7s 
 
    setInterval(cycleImages, 7000); 
 
})
.hero-cycler { 
 
    position: relative; 
 
} 
 
.hero-cycler img { 
 
    position: absolute; 
 
    z-index: 1 
 
} 
 
.hero-cycler img.active { 
 
    z-index: 3 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<div class="hero-cycler"> 
 
    <img class="active" alt="Tips qualified Client 1" src="https://unsplash.it/300/200/?image=0"> 
 
    <img alt="Tips qualified Client 2" src="https://unsplash.it/300/200/?image=1"> 
 
</div>

(브라우저 콘솔의 빠른 검사는 당신에게 오류 표시 것 : Uncaught ReferenceError: cycleImages is not defined을하는 귀하의 질문에 포함하는 것이 매우 도움이되었을 것입니다)