admin管理员组文章数量:1025244
I want to set body overflow to hidden when "popup" class was used. And called this class by JavaScript. As my CSS it don't work.
Can i have "body" tag nested in my class like this?
#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;
}
}
My example is when you click on Facebook photos, it will appear to full screen and locked scrolling. Thanks all helps
I call it like this.
<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 is photo id.
In photo.php it return html content <div class="popup">...my content...</div>
I want to set body overflow to hidden when "popup" class was used. And called this class by JavaScript. As my CSS it don't work.
Can i have "body" tag nested in my class like this?
#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;
}
}
My example is when you click on Facebook photos, it will appear to full screen and locked scrolling. Thanks all helps
I call it like this.
<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 is photo id.
In photo.php it return html content <div class="popup">...my content...</div>
- "Can i have "body" tag nested in my class like this?" NO. – Rahul Desai Commented Feb 12, 2014 at 9:02
-
When and How your
popup
class was used? – Felix Commented Feb 12, 2014 at 9:03 -
Thanks everyone It worked when i add
$('body').css('overflow', 'hidden');
to getphoto function – brendan Commented Feb 12, 2014 at 9:26 - Yes, it worked but scrolling is not visible. how to do it visible but locked it like Facebook photo viewer – brendan Commented Feb 13, 2014 at 10:32
-
@brendan try
$("body").css("overflow", "auto");
– Rahul Desai Commented Feb 13, 2014 at 11:46
6 Answers
Reset to default 3Can i have "body" tag nested in my class like this? No.
When popup
class is called, use jQuery .css()
this way:
$("body").css("overflow", "hidden");
More Info: http://api.jquery./css/
You can't use CSS
like that. You can however have a class called overflow-hidden
in your css which just sits like this:
.overflow-hidden{
overflow:hidden !important;
}
Then in jQuery:
$('.popup').click(function(){
$('body').addClass('overflow-hidden');
});
You can also use
toggleClass()
and
removeClass()
so you can addClass()
when you want to give it the css class then removeClass()
once the popup has gone.
No , you cant use css like that
if($('.popup').is(':visible')){
$("body").css('overflow', 'hidden');
}
or
$('.popup').click(function(){
$("body").css('overflow', 'hidden');
});
On close of your popup or else condition
$("body").css('overflow', 'yourchoice');
You can use jQuery like this:
$('body').filter(function(){
return $(this).find('.popup').is(':visible')
}).css('overflow','hidden');
You can't use nested css like in your example.
You can use addClass
and removeClass
in your jquery
.bodyOverflow() {
overflow:hidden;
}
And in jquery
$('.popup').on('click', function(){
$('body').addClass('bodyOverflow');
});
Something like this?
DEMO http://jsfiddle/pwzaT/
JQUERY
$('button#show').on('click', function(){
$('.popup').fadeIn(300);
$('body').css('overflow','hidden');
});
$('button#hide').on('click', function(){
$('.popup').fadeOut(300);
$('body').css('overflow','auto');
});
I want to set body overflow to hidden when "popup" class was used. And called this class by JavaScript. As my CSS it don't work.
Can i have "body" tag nested in my class like this?
#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;
}
}
My example is when you click on Facebook photos, it will appear to full screen and locked scrolling. Thanks all helps
I call it like this.
<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 is photo id.
In photo.php it return html content <div class="popup">...my content...</div>
I want to set body overflow to hidden when "popup" class was used. And called this class by JavaScript. As my CSS it don't work.
Can i have "body" tag nested in my class like this?
#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;
}
}
My example is when you click on Facebook photos, it will appear to full screen and locked scrolling. Thanks all helps
I call it like this.
<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 is photo id.
In photo.php it return html content <div class="popup">...my content...</div>
- "Can i have "body" tag nested in my class like this?" NO. – Rahul Desai Commented Feb 12, 2014 at 9:02
-
When and How your
popup
class was used? – Felix Commented Feb 12, 2014 at 9:03 -
Thanks everyone It worked when i add
$('body').css('overflow', 'hidden');
to getphoto function – brendan Commented Feb 12, 2014 at 9:26 - Yes, it worked but scrolling is not visible. how to do it visible but locked it like Facebook photo viewer – brendan Commented Feb 13, 2014 at 10:32
-
@brendan try
$("body").css("overflow", "auto");
– Rahul Desai Commented Feb 13, 2014 at 11:46
6 Answers
Reset to default 3Can i have "body" tag nested in my class like this? No.
When popup
class is called, use jQuery .css()
this way:
$("body").css("overflow", "hidden");
More Info: http://api.jquery./css/
You can't use CSS
like that. You can however have a class called overflow-hidden
in your css which just sits like this:
.overflow-hidden{
overflow:hidden !important;
}
Then in jQuery:
$('.popup').click(function(){
$('body').addClass('overflow-hidden');
});
You can also use
toggleClass()
and
removeClass()
so you can addClass()
when you want to give it the css class then removeClass()
once the popup has gone.
No , you cant use css like that
if($('.popup').is(':visible')){
$("body").css('overflow', 'hidden');
}
or
$('.popup').click(function(){
$("body").css('overflow', 'hidden');
});
On close of your popup or else condition
$("body").css('overflow', 'yourchoice');
You can use jQuery like this:
$('body').filter(function(){
return $(this).find('.popup').is(':visible')
}).css('overflow','hidden');
You can't use nested css like in your example.
You can use addClass
and removeClass
in your jquery
.bodyOverflow() {
overflow:hidden;
}
And in jquery
$('.popup').on('click', function(){
$('body').addClass('bodyOverflow');
});
Something like this?
DEMO http://jsfiddle/pwzaT/
JQUERY
$('button#show').on('click', function(){
$('.popup').fadeIn(300);
$('body').css('overflow','hidden');
});
$('button#hide').on('click', function(){
$('.popup').fadeOut(300);
$('body').css('overflow','auto');
});
本文标签: javascriptHow i set body overflow hidden when some class calledStack Overflow
版权声明:本文标题:javascript - How i set body overflow hidden when some class called - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745528696a2154649.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论