My attempt to create an image preview effect using JavaScript involves opening any image clicked in full screen mode. The code centers the image based on its size.
position: fixed;
top: 50%;
left: 50%;
Simplified Javascript | View All | Result
el.style.margin = "-" + el.height / 2 + "px -" + el.width / 2 + "px";
In Firefox, this code works properly. However, in Webkit browsers, the image is pushed into the top-left corner with negative margins. Why does this JavaScript fail in Webkit browsers and how can I rectify it?