Pregunta

Quiero unir un elemento con una función a través del método LIVE (). La función se entiende solo bien solo por primera vez. Creo que tengo que desviar este elemento de cualquier evento y rebotar la misma función, ¡pero no sé cómo hacerlo!

Aquí está el código:

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); 

¿Fue útil?

Solución

the first: NEVER, EVER, EVER do like that.

You have to cache your data and don't jump all time into the dom!!!

second: in my opinion live is deprecated -so you can use on and off

try that:

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)
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top