사진, 동영상, PDF 문서가 포함 된 '아이콘'을 통해 이전 (다음 버튼으로)을 뒤집을 수있는 jQuery 갤러리를 만들려고합니다. 다음과 같이Jquery의 재귀/자동 실행 기능이 Firebug에서 다르게 동작합니다.
내 전략은 다음과 같습니다
- 이 경우
- ,
- 실제 내용은 HTML 문자열을 반환하는 아약스 콜백에서 온다, 아이콘의 실제 내용의 무지 jQuery를 계속 내 PHP 코드가 그렇게 결정하면 해당 버튼이있는 경우
- 버튼에 클릭 이벤트를 바인딩하면
- HTML 문자열에 이전 및/또는 다음 버튼이있을 수 있습니다. 클릭 이벤트가 m에 대한 재귀 호출을 만듭니다. 새 아이콘을 표시하는 ainLoop(). 나는 방화범 디버거에() 회 돌이를 단계별로 때
function mainLoop() { if (icons[newIndex] !== IFM_APPENDED) { // tests whether this icon has already been loaded $.ajax({ type: 'POST', url: '/callback/div_supply', data: {iconindex: newIndex}, success: function(data) { $('#jquery-lightbox').append(data); // inserts new icon into the DOM icons[newIndex] = IFM_APPENDED; // registers that this icon has been loaded if ($('#icon'+newIndex+' .prev-button').length !== 0) { // test if the previous button is present $('#icon'+newIndex+' .prev-button').click(function() { oldIndex = newIndex; newIndex -= 1; mainLoop(); }); // END $('#icon'+newIndex+' .prev-button').click() } // END if ($('#icon'+newIndex+' .prev-button').length !== 0) if ($('#icon'+newIndex+' .next-button').length !== 0) { // test if the previous button is present $('#icon'+newIndex+' .next-button').click(function() { oldIndex = newIndex; newIndex += 1; mainLoop(); }); // END $('#icon'+newIndex+' .prev-button').click() } // END if ($('#icon'+newIndex+' .prev-button').length !== 0) } // END succes: }); // END $.ajax } // END if (icons[newIndex] !== IFM_APPENDED) $('#icon'+oldIndex).hide(); // hide the old icon $('#icon'+newIndex).show(); // hide the new icon } $(document).ready(function() { // Hide some elements to avoid conflict with overlay in IE. These elements appear above the overlay. $('embed, object, select').css({ 'visibility' : 'hidden' }); $("#gallery li").click(function() { _set_interface(); mainLoop(); }); // END $("#gallery a").click(function }); // END $(document).ready(function()
이 코드는 잘 작동 : 여기
는 코드입니다.
그러나 실행하면 스크립트가 중단됩니다. 또한 $ (document) .ready (function())을 밟았을 때 매달리기도합니다. Firebug를 끌 수있는 console.log() 호출이 없습니다.
내가 잘못 생각하는 부분이 있습니다. 설정 한 재귀
가 무엇이 잘못 가고
스테핑이 작동하지 않는다면, 많은'console.log' 함수를 추가하여 코드가 매달리기 시작하는 곳을 보거나'mainLoop()'에 주석 처리를 시작하십시오. 기능이 작동 할 때까지 계속 작동하고 병목 현상이 발생한 위치를 확인하십시오. – h2ooooooo
감사합니다. h2o, 나는 재귀 적 클릭 이벤트를 주석 처리했으며 문제를 일으키지 않았 음을 알게되었습니다. 사실, .show() 메서드는 표시를 차단하지 못합니다. 그러나 문제가 해결되었습니다. 아직도 이걸로 내 열을 긁적 ... –
당신이 그것을 알아 냈기 때문에 기쁩니다 (적어도 지금은 문제가 돌아올 때까지). – h2ooooooo