我的div在隐藏时显示。我在摇动div之前检查了很多条件。我的div的可见度是假的,但它仍然显示出震动效果。这是完整的代码。
HTML:
<div id="EnableCookie" runat="server" class="cookieMsg">
Please enable your browser cookie and refresh the page to view BBA Web site.
</div>
CSS:
.cookieMsg {
color: black;
text-align: justify;
width: 50%;
margin: 2% 25%;
line-height: 20px;
display: block;
font-family: Arial,Helvetica,sans-serif;
font-style: italic;
background: white;
padding-top: 10px;
padding-bottom: 10px;
padding-right: 10px;
padding-left: 10px;
display: none;
}
JS:
var isShaking = false;
$(document).ready(function () {
setInterval(function () {
if (!isShaking) {
if (!$('#<% =EnableCookie.ClientID %>').css('display') != 'none') {
if ($('#<% =EnableCookie.ClientID %>').length > 0) {
isShaking = true;
$('#<% =EnableCookie.ClientID %>').effect('shake', 200, function () {
isShaking = false;
});
}
}
}
}, 3000);
});
我的div不应该显示但它显示,我在哪里犯了错误?
答案 0 :(得分:0)
测试:
if (!$('#EnableCookie').css('display') != 'none') {
表示未显示,因此显示。
将您的代码更改为:
if ($('#EnableCookie').css('display') != 'none') {
或者:
if ($('#EnableCookie').is('visible')) {