-->

(jquery的)防止从DIV网页加载过程中示出((jquery) prevent div from

2019-09-22 09:20发布

如果你转到www.rambocats.com,网页加载,你会看到这个底部中心DIV显示出来的一两秒钟,然后消失。 (神说,在粉红色的字母“画廊II”)。 它应该一旦你向下滚动到页面的约2/3才会出现。 如何阻止它的初始加载过程中显示?

这里是jQuery的:

$(document).ready(function(){
var open = false;
$('#homiesSlideButton').click(function() {
    if(open === false) {
        $('#homiesSlideContent').animate({ height:'610px' });
        $(this).css('backgroundPosition', 'bottom left');
               $("#homies-wrapper img").peTransitionHilight({   // image highlight/transitions plugin
                                        slideshow:true, 
                                        transition:"all", 
                                        duration:1500, 
                                        delay:4444, boost:0.3
                                  });
        open = true;
    } else {
        $('#homiesSlideContent').animate({ height: '0px' });
        $(this).css('backgroundPosition', 'top left');
        open = false;
    }
});
});

$("#homiesSlideButton").hide();
$(window).scroll(function(){
if($(window).scrollTop()>4444){               // position on page when button appears
     $("#homiesSlideButton").fadeIn();
  }else{
     $("#homiesSlideButton").fadeOut();
  }
});  


$(window).scroll(function(){
if($(window).scrollTop()>4444){               // position on page when button disappears
     $("#homiesSlideContent").fadeIn();
  }else{
     $("#homiesSlideContent").fadeOut();
  }
});

Answer 1:

发生了什么事是,它设置为默认可见的,所以它显示的JavaScript / jQuery的运行,以隐藏它。

我倾向于对项目不应该从一开始就可见做的就是添加一个CSS类它们被设置为display: none;visibility: hidden; ,就像这样:

.hide {
    display: none;
}

然后使用jquery调用后删除类.hide() 在元素上:

$('#elementId').hide().removeClass('hide');


Answer 2:

它可以是简单的:

<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>Let's hide and show a div</title>

<style type="text/css">
#myHiddenDiv { visibility: hidden; }
</style>

</head>

<body>

<div id="myHiddenDiv">
Hidden until after the script loads. It will be imperceptible in most cases. But if    you comment out or remove the script, the div will indeed be hidden!
</div>


<script type="text/javascript">
document.getElementById('myHiddenDiv').style.visibility = 'visible';
</script>

</body>
</html>


Answer 3:

我认为这是动画的.hide()事件,尝试style="display:none;" 作为HTML的一部分$("#homiesSlideButton")元素。



Answer 4:

在CSS为您的div设置的div有物业

visibility: hidden;

当页面加载,

$("#yourDivId").show();


文章来源: (jquery) prevent div from showing during page load