Last active
April 3, 2018 05:11
-
-
Save shrekuu/14e5fedf13b5c5eaccdaea32a187202d to your computer and use it in GitHub Desktop.
toogle fullscreen when click something
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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