CSS Ease-in-out to full screen
- by Aditya Singh
I have a black background div of a size which contains an image.
<div id="Banner">
<img onclick="expand();" src="hola.jpg">
</div>
#Banner {
position:relative;
height:50px;
width:50px;
margin:0 auto;
background-color:#000000;
-webkit-transition: all 0.5s ease-in-out 0.5s;
-moz-transition: all 0.5s ease-in-out 0.5s;
-o-transition: all 0.5s ease-in-out 0.5s;
transition: all 0.5s ease-in-out 0.5s;
}
<script type="text/javascript">
function expand(){
document.getElementById('Banner').style['height'] = '250';
document.getElementById('Banner').style['width'] = '250';
}
</script>
So when the user clicks on the image, the div transitions to 250, 250.
My problem is that, i want it to to transition to full screen. The following javascript
function does expand to fullscreen but the transition effect doesn't come. I need to do it from a javascript code without jquery.
function expand(){
document.getElementById('Banner').style['position'] = 'absolute';
document.getElementById('Banner').style['height'] = '100%';
document.getElementById('Banner').style['width'] = '100%';
document.getElementById('Banner').style['top'] = '0';
document.getElementById('Banner').style['left'] = '0';
}
Please advice.
Update : Solution
Roger below has provided with an alternative solution. This takes care if the document
has already been scrolled and is another place. Will expand the div to full browser screen.
sz=getSize(); //function returns screen width and height in pixels
currentWidth=200;
currentHeight=200;
scalex=sz.W/currentWidth;
scaley=sz.H/currentHeight;
transx=0-((expandingDiv.offsetLeft+(currentWidth/2))-(sz.W/2))+document.body.scrollLeft;
transy=0-((expandingDiv.offsetTop+(cuttentHeight/2))-(sz.H/2))+document.body.scrollTop;
transx = transx.toString();
transy = transy.toString();
document.getElementById("Banner").style['-webkit-transform'] = 'translate('+transx+'px,'+transy+'px) scale('+scalex+','+scaley+')';