Skip to content

Instantly share code, notes, and snippets.

@shrekuu
Last active April 3, 2018 05:11
Show Gist options
  • Select an option

  • Save shrekuu/14e5fedf13b5c5eaccdaea32a187202d to your computer and use it in GitHub Desktop.

Select an option

Save shrekuu/14e5fedf13b5c5eaccdaea32a187202d to your computer and use it in GitHub Desktop.
toogle fullscreen when click something
// ref: https://davidwalsh.name/fullscreen
// let's bind the event on body element
var e = document.body;
e.onclick = function() {
if (prefixed(document, "fullScreen") || prefixed(document, "isFullScreen")) {
prefixed(document, "cancelFullScreen");
} else {
// note: requestFullScreen method is not on document
prefixed(e, "requestFullScreen");
}
}
function prefixed(obj, method) {
var pfx = ["webkit", "moz", "ms", "o", ""];
var p = 0, m, t;
while (p < pfx.length && !obj[m]) {
m = method;
if (pfx[p] !== "") {
m = m.substr(0, 1).toUpperCase() + m.substr(1);
}
m = pfx[p] + m;
t = typeof obj[m];
if (t != "undefined") {
pfx = [pfx[p]];
return (t == "function" ? obj[m]() : obj[m]);
}
p++;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment