2011-05-12 5 views
2

페이지의 뉴스 섹션에 뉴스 티커를 사용하고 있으며 prettyphoto 플러그인을이 뉴스와 함께 사용하려고하지만 jquery 함수가 작동하지 않습니다. < li> 항목 그들의 위치를 ​​바꿉니다. 첫 번째 항목이 마지막 될 때 jquery 함수가 뉴스 티커와 함께 작동하지 않습니다.

예를 들어 JQuery와 기능 중 어느 것도 여기에

코드

$(document).ready(function(){ 
    var first = 0; 
    var speed = 1000; 
    var pause = 3500; 

    function removeFirst(){ 
     first = $('ul#listticker li:first').html(); 
     $('ul#listticker li:first') 
     .animate({opacity: 0}, speed) 
     .fadeOut('slow', function() {$(this).remove();}); 
     addLast(first); 
    } 

    function addLast(first){ 
     last = '<li style="display:none">'+first+'</li>'; 
     $('ul#listticker').append(last) 
     $('ul#listticker li:last') 
     .animate({opacity: 1}, speed) 
     .fadeIn('slow') 
    } 

    interval = setInterval(removeFirst, pause); 

     //Codes above are for the news ticker 

    $(".news").click(function(e){ 
     e.preventDefault(); //I assign news class to links if there is no image for the news on db but it doesn't even work 
    }); 

    $("#newsdiv a[rel^='gallery']").prettyPhoto({ 
     theme:'light_rounded' 
    }); 
}); 

그리고 PHP 함수의 HTML 결과가 작동하지 않습니다

<ul id="listticker"> 
    <li> 
     <img src="http://example.com/m.../k_haber.png"><a href="#" class="news">12.05.2011</a><span class="news-text">Some Title</span> 
    </li> 
    <li> 
     <img src="http://example.com/../some.png"><a href="http://example.com/../news/p_some.jpg" class="news-title" rel="gallery[dd0]"> 12.05.2011</a><span class="news-text">Some Other Title</span> 
    </li> 
</ul> 

모든 아이디어가 원인 일 수도 있고 해결 방법도있을 수 있습니다.

편집 :
나는 문제가 있기 때문에 JQuery와 HTML 선택의 발생 가정합니다.

답변

0

필자는 Jquery 함수를 사용할 함수 내에서 선언 할 것을 깨달았습니다. 마지막으로 해결책을 찾았습니다. 여기

$(document).ready(function(){ 
    var first = 0; 
    var speed = 1000; 
    var pause = 3500; 

    function removeFirst(){ 
     first = $('ul#listticker li:first').html(); 
     $('ul#listticker li:first') 
     .animate({opacity: 0}, speed) 
     .fadeOut('slow', function() {$(this).remove();}); 
     addLast(first); 
    } 

    function addLast(first){ 
     last = '<li style="display:none">'+first+'</li>'; 
     $('ul#listticker').append(last) 
     $('ul#listticker li:last') 
     .animate({opacity: 1}, speed) 
     .fadeIn('slow',function(){ 
      $("a[rel^='gallery']").click(function() { 
       $.prettyPhoto.open($(this).attr("href"),"",""); 
       return false; 
      }); 
     }); 
     $(".news").click(function(e){ 
      e.preventDefault(); 
     }); 
    } 

    interval = setInterval(removeFirst, pause); 


    $("#newsdiv a[rel^='gallery']").prettyPhoto({ 
     theme:'light_rounded' 
    }); 
}); 
0

dom 준비 이벤트 외부에서 변수 및 함수 선언을 가져옵니다. http://jsfiddle.net/jfahv/

+0

덕분에 코드하지만 그것도 jsfiddle에, 하나가 작동하지 않았다, 이상한 것은 두 번째는 첫 번째가되는 1주기에서, 첫 번째가 아니라 두 번째 작품이다 그리고 두 번째 사이클 이후에는 아무 것도 작동하지 않습니다 .http : //jsfiddle.net/jfahv/6/ (내 영어는 유감입니다) –

+0

'console.log()'가 실수로 남아있을 수 있습니다. 그것은 모두 나를 위해 작동합니다 ie7-9 및 ff4 – Zlatev

0

jQuery의 ": first"선택자는 첫 번째 일치 요소를 반환하고 첫 번째 자식 요소는 반환하지 않습니다. 대신 first-child를 사용해보십시오.

+0

감사하지만 작동하지 않았다 –

관련 문제