1

これと非常によく似た質問があります。再バインドしますが、解決がわかりません。

HTMLコンテンツを左右にスライドするためのカルーセルがあります...コンテンツをスライドするための左右の画像があります。カルーセルの終わりに達すると、右側のスライド画像のクリックイベントが解除されます。左の画像をクリックすると、右の画像のクリックイベントが再度バインドされます...以下のように再バインドしても機能しないようです。クリックイベントへの参照を保存する必要があるようですが、正しく取得できません。

$(document).ready(function() {  

         //when user clicks the image for sliding right  
        $('#right_scroll img').click(function(){  

            // code for sliding content to the right, unless end is reached

                if($('#carousel_ul li:first').attr('id') == fifth_lli){ // end carousel is reached

                $('#right_scroll img').removeAttr('onmouseover');
                $('#right_scroll img').removeAttr('onmouseout');
                $('#right_scroll img').removeAttr('onmousedown');
                $('#right_scroll img').unbind('click');
                $('#right_scroll img').attr("src", "Images/gray_next_1.png");   

                };
            });  

        //when user clicks the image for sliding left  
        $('#left_scroll img').click(function(){  

            //if at end of carousel and sliding back to left, enable click event for sliding on the right...
            if($('#carousel_ul li:first').attr('id') == fifth_lli){

                $('#right_scroll img').attr("src", "Images/red_next_1.png");
                $('#right_scroll img').bind('click');   // this doesn't work.

            };      
        });  

  }); 
4

1 に答える 1

0

バインドを解除して再バインドする代わりに、移動する前にカルーセルが最後または最初にあるかどうかを確認してください。

$(document).ready(function() {
    $('#right_scroll img').click(function() {
        if ($('#carousel_ul li:first').attr('id') !== fifth_lli) {
            //slide carousel right
        }
    });
    $('#left_scroll img').click(function() {
        if ($('#carousel_ul li:first').attr('id') !== first_lli) { //changed it to first first_lli, i figure that would be the end of the left scrolling
            //slide carousel left
        }
    });
});
于 2012-11-05T12:40:06.267 に答える