• js图片全屏


    html,
            body {
                height: 100%;
            }
    
            img {
                display: block;
                margin: 100px auto 0;
                width: 900px;
                cursor: pointer;
            }
            /* webkit和IE在元素进入全屏后,会保持元素原有的尺寸,所以需要通过css伪类进行设置 */
            img:-webkit-full-screen{
                width: 100%;
                height: 100%;
            }
    
            img:-ms-fullscreen {
                width: 100%;
                height: 100%;
            }
    <img id="target" src="https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1530343927072&di=ba9a25dc1d88a14556abf44106a32a4f&imgtype=0&src=http%3A%2F%2Fup.enterdesk.com%2Fedpic_source%2Fe9%2F3d%2Ffc%2Fe93dfc90c7406e68dd72afac6dda0357.jpg"
            alt="">
    window.onload = function () {
                let img = document.querySelector('#target');
                // 监听事件 注意不同浏览器的兼容性问问题
    
           // 错误事件为:fullscreenerror , 同样注意前缀
                document.addEventListener('fullscreenchange' , function() {
                    console.log('全屏切换!')
                })
                document.addEventListener('webkitfullscreenchange' , function() {
                    console.log('全屏切换!')
                })
                document.addEventListener('mozfullscreenchange' , function() {
                    console.log('全屏切换!')
                })
                document.addEventListener('MSFullscreenChange' , function() {
                    console.log('全屏切换!')
                })
    
           // 图片点击切换全屏
                if (isFUllScreenEnabled()) {
                    img.addEventListener('click', function () {
                        if (hasFullScreenElement()) {
                            exitFullScreen();
                        } else {
                            setFullScreen(img);
                        }
                    });
                } else{
                    console.log('此浏览器不支持全屏');
                }
            }
            
            
            // 判断浏览器是否支持全屏
            function isFUllScreenEnabled() {
                return document.fullscreenEnabled || document.webkitFullscreenEnabled || document.mozFullScreenEnabled || document.msFullscreenEnabled;
            }
    
            // 判断是否有已全屏的元素
            function hasFullScreenElement() {
                return document.fullscreenElement || document.webkitFullscreenElement || document.mozFullScreenElement || document.msFullscreenElement
            }
    
            // 将目标元素设置为全屏展示
            function setFullScreen(target) {
                if (target.requestFullscreen) {
                    target.requestFullscreen();
                }
                if (target.webkitRequestFullscreen) {
                    target.webkitRequestFullscreen();
                }
                if (target.mozRequestFullScreen) {
                    target.mozRequestFullScreen();
                }
                if (target.msRequestFullscreen) {
                    target.msRequestFullscreen();
                }
            }
            
            // 文档退出全屏
            function exitFullScreen() {
                if (document.exitFullscreen) {
                    document.exitFullscreen();
                }
                if (document.webkitExitFullscreen) {
                    document.webkitExitFullscreen();
                }
                if (document.mozCancelFullScreen) {
                    document.mozCancelFullScreen();
                }
                if (document.msExitFullscreen) {
                    document.msExitFullscreen();
                }
            }
  • 相关阅读:
    极简风格的LOGO,收集一波!
    如何利用AI软件中的混合器工具制作文字
    国内有哪些非常有设计感的 App?
    如何用PS制作花型背景图
    怎样去调整摄影作品的背景颜色
    如何用PS把数码拍摄的荷花照片制作成中国风的效果
    PS 抠人像如何抠得干净?
    如何用 Ps 制作毛玻璃穿透效果?
    化装品经过这样PS包装,身价立马翻10倍
    有哪些漂亮的中国风 LOGO 设计?
  • 原文地址:https://www.cnblogs.com/zard23/p/9429333.html
Copyright © 2020-2023  润新知