Отскок та же функция - PullRequest
       22

Отскок та же функция

0 голосов
/ 11 марта 2012

Я хочу связать элемент с функцией с помощью метода live (). Функция прекрасно выполняет только в первый раз. Я думаю, что мне нужно отсоединить этот элемент от любых событий и восстановить ту же функцию, но я не знаю, как это сделать!

Вот код:

var temp = function() {
    var htmlEx = "Lorem ipsum dolor sit amet, consectetur adipiscing elit.";

    $('#template_loading').fadeIn();
    $('#template_loading').queue(function() {
        $('#tp_prev').html(htmlEx);
        $('#template_container').removeClass("cur_temp");
        $('#template_container').addClass("cur_prev");
        $('#template_container').animate({"margin-left" : "0"}, 400, 'easeOutExpo');    
        $('#template_container').queue(function() {
            $('#template_loading').fadeOut();               
            $('#tp_cur').empty();               
            $('#template_container').removeClass("cur_prev");
            $('#template_container').addClass("cur_temp");  
            $('#tp_prev').empty();              
            $('#tp_cur').html(htmlEx);
            $('#tp_cur').queue(function() {
                $('#prev.pers_arrow').die();
                $('#prev.pers_arrow').live("click", temp);
                $(this).dequeue();
            });
            $(this).dequeue();
        });
        $(this).dequeue();
    });
};

$('#prev.pers_arrow').live("click", temp); 

1 Ответ

1 голос
/ 11 марта 2012

первое: НИКОГДА, НИКОГДА, НИКОГДА не делай так.

Вы должны кэшировать свои данные и не прыгать все время в дом !!!

второй: по моему мнению, в прямом эфире устарела, так что вы можете использовать на и выкл

попробуйте это:

var prev=$("#prev");
var pers_arrow=".pers_arrow";
    var temp = function() {
    var htmlEx = "Lorem ipsum dolor sit amet, consectetur adipiscing elit.";
    var template_loading=$('#template_loading');

    template_loading
        .fadeIn()
        .queue(function() {
            $('#tp_prev').html(htmlEx);
            var template_container=$('#template_container');
            template_container
                .removeClass("cur_temp")
                .addClass("cur_prev")
                .animate({"margin-left" : "0"}, 400, 'easeOutExpo')
                .queue(function() {
                    template_loading.fadeOut();               

                    template_container.removeClass("cur_prev").addClass("cur_temp");  
                    $('#tp_prev').empty();    
                    //you can don't use it - because .html() method already will clean container         
                    //$('#tp_cur').empty();      
                    $('#tp_cur').html(htmlEx).queue(function() {
                        prev.off("click",pers_arrow,temp).on("click",pers_arrow,temp);
                        $(this).dequeue();
                    });
                    $(this).dequeue();
                });
            $(this).dequeue();
        });
};
prev.off("click",pers_arrow,temp).on("click",pers_arrow,temp)
...