为什么jquery在隐藏之前会在页面加载时闪烁.hide flicker

时间:2014-03-06 17:48:41

标签: jquery

我正在学习查询,如果存在类名,我会隐藏一个按钮,但是当我加载页面并且存在类名时,按钮会在隐藏之前显示为短暂的第二个,我做错了什么,是否有办法我可以加快速度吗?

这是我的代码

jQuery(document).ready(function($){
  // If the imagelinks with classname clonedInput are shown, then hide the add image button
  if ( $(".clonedInput").length) {
      $('.add-logo-button').hide();
  }
  // When you click clone. hide the button
  $('.add-logo-button').click(function(){
      $(".add-logo-button").hide();
  });
  // When you click remove. show the button
  $('.remove-logo').click(function(){
      $(".add-logo-button").show();
  });
});

1 个答案:

答案 0 :(得分:0)

首次加载时,执行jquery隐藏此元素需要一些时间。这一刻,直到它执行jquery隐藏它将显示在页面中。

所以你需要为这个元素使用css(例如内联样式display:none)你在页面加载中隐藏的内容。如果你内联css然后它将在html加载中执行,它将不会出现任何时刻。

相关问题