我想在使用“弹出”类时将主体溢出设置为隐藏。并通过JavaScript调用了此类。作为我的CSS,它不起作用。
我可以像这样在我的班级中嵌套“ body”标签吗?
#CSS
.popup {
display: table;
height: 100% !important;
table-layout: fixed;
width: 100%;
position: fixed;
top: 0px;
bottom: 0px;
z-index: 400;
body {
overflow: hidden!important;
}
}
我的示例是,当您单击Facebook照片时,它将以全屏显示并锁定滚动。谢谢大家的帮助
我这样称呼它。
<a href="#" onclick="getphoto(int)">Click to view larger</a>
的JavaScript
function getphoto(inputString) {
$('body').css('overflow', 'hidden');
if(inputString.length == 0||false) {
$('#suggestions3').fadeOut(); // Hide the suggestions box
}else{
//alert(inputString);
$.post("p/photo.php", {queryString: ""+inputString+""}, function(data) { // Do an AJAX call
$('#suggestions3').fadeIn(); // Show the suggestions box
$('#suggestions3').html(data); // Fill the suggestions box
});
}
}
inputString是照片ID。
在photo.php中,它返回html内容
<div class="popup">...my content...</div>
最佳答案
我可以像这样在我的班级中嵌套“ body”标签吗?没有。
调用popup
类时,请通过以下方式使用jQuery .css()
:
$("body").css("overflow", "hidden");
更多信息:http://api.jquery.com/css/
关于javascript - 当某个类(class)召集时,我如何隐藏 body 溢出,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/21723076/