慢jQuery - 加载时间长?

时间:2014-11-01 00:14:53

标签: jquery

我完全不熟悉jQuery。我可能错过了一些基本的东西,而我的代码看起来就像一块垃圾。如果你愿意,可以随意忽略这个。

我写了这段代码,但有时候,浏览器根本没有回复我的" clics"并没有做任何事情。然后它运作正常,一段时间后再次卡住了。 有任何想法吗?非常感谢!

$(document).ready(function() {

$("#text2").hide();
$("#text3").hide();

$('#ball1').click(function() {
    $('#text2').fadeOut('slow');
    $('#text3').fadeOut('slow');
    $('#text1').fadeIn('slow');
    $("#arrow").animate({left:'40px'});

 $('#ball2').click(function() {
    $('#text1').fadeOut('slow');
    $('#text3').fadeOut('slow');
    $('#text2').fadeIn('slow');
    $("#arrow").animate({left:'400px'});

 $('#ball3').click(function() {
    $('#text2').fadeOut('slow');
    $('#text1').fadeOut('slow');
    $('#text3').fadeIn('slow');
    $("#arrow").animate({left:'770px'});
});
});
  });
  });

1 个答案:

答案 0 :(得分:1)

我认为你的范围搞砸了。你忘了关闭每个函数,而是将它们全部嵌入到第一个函数中。它可能很慢,因为每次单击#ball1时都会继续分配点击事件。替换为:

$(document).ready(function() {

  $("#text2").hide();
  $("#text3").hide();

  $('#ball1').click(function() {
    $('#text2').fadeOut('slow');
    $('#text3').fadeOut('slow');
    $('#text1').fadeIn('slow');
    $("#arrow").animate({left:'40px'});
  });

  $('#ball2').click(function() {
    $('#text1').fadeOut('slow');
    $('#text3').fadeOut('slow');
    $('#text2').fadeIn('slow');
    $("#arrow").animate({left:'400px'});
  });

  $('#ball3').click(function() {
    $('#text2').fadeOut('slow');
    $('#text1').fadeOut('slow');
    $('#text3').fadeIn('slow');
    $("#arrow").animate({left:'770px'});
  });

});