Javascript 如何使用jquery或alternative隐藏div?
好的,这是我的代码: HTML JS 当我点击我的按钮时,我想切换#overlay-2的可见性 我该怎么做? 不确定Javascript 如何使用jquery或alternative隐藏div?,javascript,jquery,html,css,Javascript,Jquery,Html,Css,好的,这是我的代码: HTML JS 当我点击我的按钮时,我想切换#overlay-2的可见性 我该怎么做? 不确定可见性:hidden是否是css中的路径。但我确实希望它隐藏在页面加载,因为它将覆盖整个屏幕与黑暗的覆盖 任何帮助都将不胜感激! 谢谢使用显示:无而不是可见性:隐藏这应该可以: $('.custom_class_1').click(function() { $('#overlay-2').toggle(); }); 在您的主css中,正如其他人建议的那
可见性:hidden
是否是css中的路径。但我确实希望它隐藏在页面加载,因为它将覆盖整个屏幕与黑暗的覆盖
任何帮助都将不胜感激!
谢谢使用
显示:无代码>而不是可见性:隐藏代码>这应该可以:
$('.custom_class_1').click(function() {
$('#overlay-2').toggle();
});
在您的主css中,正如其他人建议的那样,您应该使用Display:none
代替Visibility:hidden
如果您使用的是JQuery,那么请使用.hide()方法:
$(“#overlay-2”).hide()
这里是一个纯CSS解决方案-
HTML
从优秀页面。display:none代替visibility或在fadeIn()之前调用hide():$(“#overlay-2”).hide().fadeIn(300);toggle
的动画签名尚未删除。哦,好的,那是他们当时删除的唯一部分吗?不,我的意思是,.toggle()
切换显示(带动画和不带动画)已保留,只有分配单击处理程序的.toggle(函数[,函数…])
已删除(可以使用迁移插件还原)。好的,这更有意义。谢谢。嘿@JustinM谢谢,看起来它走上了正确的轨道。不幸的是,我对Jquery还很陌生,不知道如何使用切换功能。如果你有时间,你能帮我完成更多的代码吗,或者参考一个我可以学习的链接:)使用hide意味着您需要跟踪状态,以便在隐藏状态时调用.show()。toggle()为您处理此问题
#overlay-2 {
height: 100%;
width: 100%;
position: fixed;
left: 0;
top: 0;
background: none repeat scroll 0 0 #000000;
opacity: 0.85;
z-index: 10;
visibility: hidden;
}
$('.custom_class_1').click(function() {
$('#overlay-2').fadeIn(300);
});
$('.custom_class_1').click(function() {
$('#overlay-2').toggle();
});
<input type='checkbox' id='inputstyle'></input>
<div class='centerme'>
<label for="inputstyle"><span>Click Me</span></label>
</div>
<div class='hideme'></div>
.centerme {
width: 80px;
margin: 0px auto;
}
.hideme {
width: 100px;
height: 100px;
background-color: red;
margin: 10px auto;
}
.clickme:active > .hideme {
display: none;
}
input[type=checkbox]:checked ~ .hideme {
display: none;
}
input[type=checkbox] {
display: none;
}
input[type="checkbox"] + div label span {
display:inline-block;
width:80px;
height:30px;
background-color: gray;
border-right: 2px solid black;
border-bottom: 2px solid black;
line-height: 30px;
color: white;
text-align: center;
}