Reputation: 934
I have a div that I want to go full-screen (100% width/height of Window size) onClick of a button. How would I go about this using Javascript/jQuery?
Upvotes: 0
Views: 7080
Reputation: 2183
This is an alternate to the answer marked as correct. Plus it gives him what he asked for to close the div.
Using toggle class is much easier than having your css in your jquery. Do everything you can do to keep css separate from JavaScript.
For some reason my https is effecting loading of the JavaScript on load of that jsfiddle page. I clicked on the Shield icon in chrome address bar and chose to run scripts.
Something like
$('#buttonID').click(function() {
$("div > div").toggleClass("Class you want to add");
});
Upvotes: 0
Reputation: 8930
$('div').click(function() {
$(this).css({
position:'absolute', //or fixed depending on needs
top: $(window).scrollTop(), // top pos based on scoll pos
left: 0,
height: '100%',
width: '100%'
});
});
Upvotes: 2
Reputation: 94141
$('div').click(function(){
var win = $(window),
h = win.height(),
w = win.width();
$(this).css({ height: h, width: w });
});
Upvotes: 0
Reputation: 12916
I would do this:
$('#idOfDiv').click(function() {
$(this).css({position:'fixed', height: '100%', width: '100%'});
});
jsfiffle: http://jsfiddle.net/P6tgH/
Upvotes: 0
Reputation: 6406
What have you tried? What didn't work? Take a look at that:
$('#box').on('click',function(e){
$(this).css({
width:"100%",
height:"100%"
});
});
Upvotes: 0
Reputation: 4177
$('div.yourdivclass').click(function(){
$(this).css('height','100%').css('width','100%');
})
Upvotes: 0