Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/fsharp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 单击方法同时将所有内容都打开_Javascript_Jquery - Fatal编程技术网

Javascript 单击方法同时将所有内容都打开

Javascript 单击方法同时将所有内容都打开,javascript,jquery,Javascript,Jquery,我有一个按钮点击功能,它应该像普通的javascript函数一样运行,一个接一个地启动所有函数,但它一次启动所有函数。这就是Date.getTime函数在控制台中显示的内容。那么如何使它不是同时发射,而是一个接一个地发射呢 $('#slider-menu li:last-child a').click(function(e) { console.log("1# " + Math.round(new Date().getTime() / 1000)); e.preventDefau

我有一个按钮点击功能,它应该像普通的javascript函数一样运行,一个接一个地启动所有函数,但它一次启动所有函数。这就是Date.getTime函数在控制台中显示的内容。那么如何使它不是同时发射,而是一个接一个地发射呢

$('#slider-menu li:last-child a').click(function(e) {
    console.log("1# " + Math.round(new Date().getTime() / 1000));
    e.preventDefault();
    console.log("2# " + Math.round(new Date().getTime() / 1000));

    $('#slider-menu .span12 li').removeClass("active");
    console.log("3# " + Math.round(new Date().getTime() / 1000));

    $('#slider-menu li:last-child').addClass("active");
    console.log("4# " + Math.round(new Date().getTime() / 1000));

    $('.trikampis').remove();
    console.log("5# " + Math.round(new Date().getTime() / 1000));

    var ilgis3 = $('#slider-menu .active').width() / 2;
    console.log("6# " + Math.round(new Date().getTime() / 1000));

    $(this).after("<div class='trikampis'></div>");
    console.log("7# " + Math.round(new Date().getTime() / 1000));

    $('#slider-menu .trikampis').css("border-left-width", ilgis3 + "px");
    console.log("8# " + Math.round(new Date().getTime() / 1000));

    $('#slider-menu .trikampis').css("border-right-width", ilgis3 + "px");
    console.log("9# " + Math.round(new Date().getTime() / 1000));

    $('#slider-menu ul').css("border-bottom-color", $('#slider-menu li.active a').css("background"));
    console.log("10# " + Math.round(new Date().getTime() / 1000));

    if ($('.slider-1').length !== 0) {
        $('.slider-1').addClass("slider-1-a");
        $('.slider-1').removeClass("slider-1");
        console.log("11# " + Math.round(new Date().getTime() / 1000));

    }
    if ($('.slider-2').length !== 0) {
        $('.slider-2').addClass("slider-2-a");
        $('.slider-2').removeClass("slider-2");
        console.log("11# " + Math.round(new Date().getTime() / 1000));

    }
    if ($('.slider-3-a').length !== 0) {
        $('.slider-3-a').addClass("slider-3");
        $('.slider-3-a').removeClass("slider-3-a");
        console.log("11# " + Math.round(new Date().getTime() / 1000));

    }
    $('.slider').hide();
    console.log("12# " + Math.round(new Date().getTime() / 1000));

    $("#preloader").show(); // will fade out the white DIV that covers the website.
    console.log("13# " + Math.round(new Date().getTime() / 1000));

    $("#status").show(); // will first fade out the loading animation
    console.log("14# " + Math.round(new Date().getTime() / 1000));

    $('.slider').load('/we-have-puppies #product-slideshow');
    console.log("15# " + Math.round(new Date().getTime() / 1000));

    $.getScript('http://bisonai.infoaleja.lt/wp-content/themes/bisonai/js/slideris.js');
    console.log("16# " + Math.round(new Date().getTime() / 1000));

    $('.pagr-info-blokas h3 a').css("color", $('#slider-menu li.active a').css("background"));

    console.log("17# " + Math.round(new Date().getTime() / 1000));

    $("#status").fadeOut(); // will first fade out the loading animation
    $("#preloader").delay(700).fadeOut("slow"); // will fade out the white DIV that covers the website.
    $('.slider').fadeIn();
    console.log("18# " + Math.round(new Date().getTime() / 1000));

});

您正在查找console.timePERIOD\u名称

像这样使用它:

console.time('t')
if ($('.slider-1').length !== 0) {
        $('.slider-1').addClass("slider-1-a");
        $('.slider-1').removeClass("slider-1");
        console.log("11# " + Math.round(new Date().getTime() / 1000));}
console.timeEnd('t')
//Outputs t: 0.010ms

你是否期望在两次加载之间都有延迟?它正在一个接一个地执行,但计算机的速度足够快,可以在毫秒内完成,而你正在通过计算来缩短时间。总而言之,我需要ajax加载函数下面的部分立即启动,然后加载ajax脚本。现在看起来一切都是同时启动的。动画是异步进行的,你认为它们是同步进行的。这就是完成回调的目的。@sergioadh您现在说得对。我已经改变了它,没有轮和没有分裂。01 1376690981469 02 1376690981469 03 1376690981469 04 1376690981470 05 1376690981470 06 1376690981471 07 1376690981472 08 1376690981472 09 1376690981472 10 1376690981473 11 1376690981474 1376690981474 1376690981474 14 1376690981474 15 1376690981472015 16 13766909822086 17 1376690982087我喜欢重大的变化。因为ajax调用应该需要更长的PauseGod点和控制台。时间't',我已经检查过,ajax调用前的部分持续时间是3.000ms,从ajax调用到结束的部分是~700ms。但一切都会在一瞬间发生变化..?这是因为3ms速度非常快。尝试使用setTimeout并使用回调