I'm following this great tutorial from SitePoint to implement fullscreen-on-click on some images of my site.
My code is very similar to the example provided by SitePoint, but here is my code:
HTML
<figure class="fullscreenOnClick">
<img src="https://dw-uploads.s3.eu-central-1.amazonaws.com/photos/originals/359c0687ae12e32bb5f26f2005763b73">
</figure>
JS
$('.fullscreenOnClick').on('click', function(e) {
e.preventDefault;
var elem = this;
if (elem.requestFullscreen) {
elem.requestFullscreen();
} else if (elem.msRequestFullscreen) {
elem.msRequestFullscreen();
} else if (elem.mozRequestFullScreen) {
elem.mozRequestFullScreen();
} else if (elem.webkitRequestFullscreen) {
elem.webkitRequestFullscreen();
} else {
alert("Sorry, your browser is too old and doesn't support fullscreen :-(")
}
});
http://jsfiddle.net/xnyj9wr5/ (not working - again, see SitePoint example)
The problem
My problem is that Firefox and IE display the fullscreen image as I expect: the image gets shown in its original size, centered.
Chrome is causing the issue: the image just get centered on the black background, keeping its current size.
How can I get Chrome to do fullscreen like Firefox and IE?
Please note: I must apply the fullscreen effect to the outer element, not to the img itself, because otherwise the image gets stretched.
width=100
both show the image at that size in fullscreen. Firefox did not show the image in its original size for me. As a side note the reason the fiddle doesn't work is because the fiddle iframe does not haveallowfullscreen
set.