架构师_程序员_码农网

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 11075|回复: 3

[Jquery] jquery 全屏插件“jQuery Fullscreen Plugin”使用

[复制链接]
发表于 2017-8-14 16:34:52 | 显示全部楼层 |阅读模式
今天工作中,遇到了一个网页全屏显示的需求,于是查了一下百度,发现了一个网页全屏显示的jQuery插件:jquery FullScreen Plugin 。他可以实现网页的全屏显示,适用各种不同的浏览器,包括FF 10, Chrome 和 Safari,它用于为用户提供了一个更容易阅读的网页版本,可缩放<canvas>和<video>元素。

jQuery Fullscreen Plugin

Description

This jQuery plugin provides a simple to use mechanism to control the new fullscreen mode of modern browsers. Currently only newer Webkit-based browsers (Like Chrome and Safari), Firefox and IE11+ provide this new fullscreen feature.

Usage

Entering Fullscreen mode

You can either switch the whole page or a single HTML element to fullscreen mode:

$(document).fullScreen(true);
$("#myVideo").fullScreen(true);
This only works when the code was triggered by a user interaction (For example a onclick event on a button). Browsers don't allow entering fullscreen mode without user interaction.

Exiting Fullscreen mode

Fullscreen mode is always exited via the document but this plugin allows it also via any HTML element. The owner document of the selected HTML element is used then:

$(document).fullScreen(false);
$("#myVideo").fullScreen(false);
Querying Fullscreen mode

Simply pass no argument to the fullScreen method to query the current state. The method returns the current fullscreen element (or true if browser doesn't support this) when fullscreen mode is active, false if not active or null when the browser does not support fullscreen mode at all. So you can use this method also to display a fullscreen button only when the browser supports fullscreen mode:

$("#fullscreenButton").toggle($(document).fullScreen() != null))
Toggling Fullscreen mode

The plugin provides another method for simple fullscreen mode toggling:

$(document).toggleFullScreen();
Notifications

The plugin triggers a fullscreenchange event on the document when the fullscreen mode has been changed. If the browser rejected a fullscreen state change then the plugin triggers a fullscreenerror event on the document. Example:

$(document).bind("fullscreenchange", function() {
    console.log("Fullscreen " + ($(document).fullScreen() ? "on" : "off"));
});

$(document).bind("fullscreenerror", function() {
    alert("Browser rejected fullscreen change");
});
Fullscreen iframe

Entering fullscreen mode from within an iframe is not allowed by default but it can be enabled with a few attributes on the iframe:

<iframe src="iframe.html" webkitAllowFullScreen mozAllowFullScreen allowFullScreen>
</iframe>
Known issues

In IE 11 an empty page is displayed when entering fullscreen from within an iframe. No idea why. Any help is welcome.
In Safari (At least in Safari 7) no keyboard input is allowed in fullscreen mode.

github地址:https://github.com/kayahr/jquery-fullscreen-plugin

游客,如果您要查看本帖隐藏内容请回复





上一篇:Linux命令:创建软连接 ln -s
下一篇:JAVA Error occurred during initialization of VM 错误的解决方法
码农网,只发表在实践过程中,遇到的技术难题,不误导他人。
发表于 2017-8-14 17:08:18 | 显示全部楼层
你都难道就是传说中的全栈工程师!
码农网,只发表在实践过程中,遇到的技术难题,不误导他人。
发表于 2017-11-25 14:35:17 | 显示全部楼层
111111111111111111

评分

参与人数 1MB -1 贡献 -1 收起 理由
QWERTYU -1 -1 请勿灌水,提高回帖资料是每位会员应尽的义.

查看全部评分

码农网,只发表在实践过程中,遇到的技术难题,不误导他人。
发表于 2018-2-28 04:11:07 | 显示全部楼层
好像好厉害的样子
码农网,只发表在实践过程中,遇到的技术难题,不误导他人。
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

免责声明:
码农网所发布的一切软件、编程资料或者文章仅限用于学习和研究目的;不得将上述内容用于商业或者非法用途,否则,一切后果请用户自负。本站信息来自网络,版权争议与本站无关。您必须在下载后的24个小时之内,从您的电脑中彻底删除上述内容。如果您喜欢该程序,请支持正版软件,购买注册,得到更好的正版服务。如有侵权请邮件与我们联系处理。

Mail To:help@itsvse.com

QQ|手机版|小黑屋|架构师 ( 鲁ICP备14021824号-2 )|网站地图

GMT+8, 2024-4-20 16:02

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表