x5-fullscreen

Right now Apple, Microsoft, Google and Mozilla are pushing towards “flat” design by slimming down the visual clutter of their applications. Despite this minimalist trend, it is unavoidable that at least a few buttons and menu options will remain in browsers.

目前,苹果,微软,谷歌和Mozilla正在通过减少其应用程序的视觉混乱来推动“扁平化”设计。 尽管有这种最低限度的趋势,但不可避免的是浏览器中至少会保留一些按钮和菜单选项。

Those same browsers are being used to display games, video and other content, where the presence of window “chrome” is deeply distracting. As a separate application, Adobe Flash had a “fullscreen” mode that can take over the complete screen, but, as with most other plugin features, HTML5 is superseding it, in the form of the FullScreen API.|

那些相同的浏览器被用于显示游戏,视频和其他内容,而窗口“ chrome”的存在则使人分心。 作为单独的应用程序,Adobe Flash具有“全屏”模式,可以接管整个屏幕,但是与大多数其他插件功能一样,HTML5以FullScreen API的形式取代了它。

Like Geolocation, the Fullscreen API is permission-based: the user must explicitly request content to be displayed in fullscreen mode; it cannot be imposed on a page.  After launching fullscreen, the browser asks if the user wants to keep things that way.

与地理位置一样,全屏API也是基于权限的: 用户必须明确要求以全屏模式显示内容 ; 不能将其强加于页面上。 启动全屏后,浏览器会询问用户是否要保留这种方式。

While this works as a practical safeguard, I suspect that some web developers might still regard the Fullscreen API as the 21st century equivalent of the popup window. The reality is that fullscreen mode is not for every website.  However tempting, it is likely that most general-interest sites do not require hijacking user’s screen. In most cases, fullscreen display should be limited to instances in which the user is to be engaged without distraction for several minutes, such as:

虽然这个作品作为一个实际的保障,我怀疑有些网站开发者可能仍然把全屏API作为21 世纪相当于弹出窗口。 现实情况是并非全屏模式适用于每个网站 。 无论多么诱人,大多数有共同利益的网站都可能不需要劫持用户的屏幕。 在大多数情况下,全屏显示应仅限于几分钟内不分心地与用户互动的情况,例如:

  • Extended presentations 扩展演讲
  • Browser-driven kiosk applications 浏览器驱动的信息亭应用
  • Games 游戏类
  • Video content 影片内容

Keep in mind that the average visitor stays on a web page for less than a minute; engaging fullscreen mode should therefore be reserved for very particular applications. It’s also important to note that your content should be delivered at sufficiently high resolution to be presented across the screen: responsive images are a must when offering fullscreen mode.

请记住,普通访问者在网页上停留的时间少于一分钟; 因此,应为非常特殊的应用保留全屏模式。 同样重要的是要注意,您的内容应以足够高的分辨率交付,以在屏幕上呈现:提供全屏模式时,必须提供响应图像 。

浏览器支持 (Browser Support)

The Fullscreen API has good browser support on the desktop: Firefox 10+, Chrome 15+, Internet Explorer and 11 and Safari 5.1 all support the API. The issue right now is that each browser interprets the existing API with slight modifications to the syntax, just like CSS vendor prefixes. For example, the requestFullscreen method:

全屏API在桌面上具有良好的浏览器支持:Firefox 10 +,Chrome 15 +,Internet Explorer和11和Safari 5.1均支持该API。 现在的问题是,每个浏览器都对CSS进行了一些微小的修改,就解释了现有的API,就像CSS vendor prefixs一样 。 例如, requestFullscreen方法:

element.requestFullscreen();
element.mozRequestFullScreen();
element.webkitRequestFullscreen();
element.msRequestFullscreen();

Note that requestFullscreen() starts with a lowercase letter in its standard form, and screen has a lowercase s, but the method begins with a capital letter when a prefix is added, keeping to JavaScript’s camelCase convention. Because of the subtle differences in the syntax, I suggest you copy and paste the methods to avoid typos.

请注意, requestFullscreen()以其标准格式的小写字母开头,而screen具有小写的s ,但是在添加前缀时,该方法以大写字母开头,并遵守JavaScript的camelCase约定。 由于语法上的细微差异,建议您复制并粘贴方法以避免输入错误。

Internet Explorer pre version 11 has its own, very different, proprietary method, which I’ll address in a future article.

Internet Explorer 11以前的版本有其自己的,非常不同的专有方法,我将在以后的文章中介绍。

全屏支持编码 (Coding For FullScreen Support)

Now that we understand the basic requirements for the FullScreen API, let’s look at the ways it might be used in browsers that support it.  First, we need to ensure that the right method is called for the appropriate browser. We’ll do that in a function:

现在,我们了解了FullScreen API的基本要求,让我们看一下在支持它的浏览器中可能使用它的方式。 首先,我们需要确保为适当的浏览器调用正确的方法。 我们将在一个函数中执行此操作:

function launchFullScreen(element) {if (element.requestFullscreen) {
element.requestFullscreen();}else if (element.mozRequestFullScreen) {
element.mozRequestFullScreen();}else if (element.webkitRequestFullscreen) {
element.webkitRequestFullscreen();}else if (element.msRequestFullscreen) {
element.msRequestFullscreen();}
}

The function takes a single argument, which defines what will be pushed into fullscreen mode. If you want the entire page to be displayed this way, the root documentElement should be passed. This action will commonly be associated with a button or link somewhere on the page:

该函数采用单个参数,该参数定义将被推送到全屏模式的内容。 如果要以这种方式显示整个页面,则应传递根documentElement 。 此操作通常与页面上某处的按钮或链接相关联:

<button onclick="launchFullScreen(document.documentElement)"> Fullscreen </button>

Using the same function, you can pass any identifiable element and its content into fullscreen mode:

使用相同的功能,可以将任何可识别的元素及其内容传递到全屏模式:

<button onclick="launchFullScreen(document.getElementById('pic'))">
Fullscreen Image </button>

Note that HTML5 video has natural fullscreen support built into the browser.

请注意, HTML5视频在浏览器中内置了自然的全屏支持。

Using fullscreen mode often implies that new CSS will be applied to the content, and/or that elements will be swapped out for an alternative high-resolution version.

使用全屏模式通常意味着将新CSS应用于内容,和/或将元素替换为替代的高分辨率版本 。

退出全屏模式 (Exiting Fullscreen Mode)

While the ESC key is a standard browser UI option to escape fullscreen mode, it’s good practice to present a visible option to do so. Note that the method swaps between CancelFullScreen (the old version of the spec) to exitFullscreen, the new version.

虽然ESC键是退出全屏模式的标准浏览器UI选项,但是最好提供一个可见的选项来退出全屏模式。 请注意,该方法在CancelFullScreen (规范的旧版本)与exitFullscreen (新版本)之间exitFullscreen

function cancelFullScreen() {if (document.exitFullscreen) {
document.exitFullscreen();} else if (document.mozCancelFullScreen) {
document.mozCancelFullScreen();} else if (document.webkitExitFullscreen) {
document.webkitExitFullscreen();} else if (document.msExitFullscreen) {
document.msExitFullscreen();}
}

Again, this is usually associated with an interface element:

同样,这通常与接口元素相关联:

<button onclick="cancelFullScreen(documentElement)">Cancel Fullscreen</button>

As you can imagine, positioning these interface elements and making them available to the user at appropriate times can become a little complicated.

您可以想象,放置这些接口元素并在适当的时间将其提供给用户可以变得有些复杂。

Keep in mind that users can still reject the initial FullScreen prompt: if they do so, the browser will fall back into standard “windowed” operation. Needless to say, the presentation of your content should continue regardless.

请记住,用户仍然可以拒绝最初的“全屏”提示:如果这样做,浏览器将退回到标准的“窗口式”操作。 不用说,无论如何,内容的呈现都应继续。

更多资源 (Further Resources)

David Storey (no relation) has an excellent, up-to-date article on using the Fullscreen API

David Storey(无关系) 撰写了一篇出色的最新文章,介绍了如何使用Fullscreen API

翻译自: https://thenewcode.com/708/Introducing-the-HTML5-FullScreen-API

x5-fullscreen

x5-fullscreen_HTML5 FullScreen API简介相关推荐

  1. 线程编程常见API简介(中)

    2019独角兽企业重金招聘Python工程师标准>>> 一.概述 在<线程编程常见API简介(上) >中讲述了有关线程创建过程中常用的 API 的使用方法,本节继续讲述有 ...

  2. WebSocket API简介

    WebSocket是html5新增加的一种通信协议,目前流行的浏览器都支持这个协议,例如Chrome,Safari,Firefox,Opera,IE等等,对该协议支持最早的应该是chrome,从chr ...

  3. web API简介(二):客户端储存之document.cookie API

    概述 前篇:web API简介(一):API,Ajax和Fetch 客户端储存从某一方面来说和动态网站差不多.动态网站是用服务端来储存数据,而客户端储存是用客户端来储存数据.document.cook ...

  4. 【Netty】NIO 网络通信 SelectionKey 常用 API 简介

    文章目录 I . SelectionKey 简介 II . SelectionKey 事件简介 III . SelectionKey 常用 API 简介 I . SelectionKey 简介 1 . ...

  5. 【Java 网络编程】TCP API 简介 ( Socket | ServerSocket )

    文章目录 I Socket API 简介 II ServerSocket API 简介 III Socket 数据交互 IV Socket 客户端操作流程 V Socket 服务器端操作流程 VI S ...

  6. java编译器使用教程_Java编译器API简介

    今天给大家分享的是Java编译器API简介,文章部分内容摘自[优锐课]学习笔记. Java编译器API Java编译器API是Java模块(称为java.compiler)的一部分.该模块包括语言模型 ...

  7. html5画电池状态,HTML5的一个显示电池状态的API简介

    这篇文章主要介绍了HTML5的一个显示电池状态的API简介,由Mozilla设计,具体的设备和浏览器支持情况还要通过检测才能确定,需要的朋友可以参考下 移动设备的份额在网络流量中在大量增长,其所贡献的 ...

  8. ZABBIX API简介及使用

    API简介 Zabbix API开始扮演着越来越重要的角色,尤其是在集成第三方软件和自动化日常任务时.很难想象管理数千台服务器而没有自动化是多么的困难.Zabbix API为批量操作.第三方软件集成以 ...

  9. Promise API 简介

    Promise API 简介 译者注: 到处是回调函数,代码非常臃肿难看, Promise 主要用来解决这种编程方式, 将某些代码封装于内部. Promise 直译为"承诺",但一 ...

最新文章

  1. c++语言中,vector容器与list容器的区别和联系?_百度知道
  2. ExtJs 备忘录(3)—— Form表单(三) [ 数据验证 ]
  3. 27年前被Nature拒稿,如今斩获诺贝尔奖!学术投稿模式再引热议:都有神奇的评审2...
  4. 最简单红米系统一键激活xposed框架教程
  5. 树网的核 Vijos1362 NOIP2007 树结构 直径 暴搜
  6. OpenGL ES之GLSL实现仿抖音“灰度滤镜”和“颠倒滤镜”效果
  7. 生理性玻璃体混浊的分类与预防控制
  8. 浅谈开发中的MVVM模式及与MVP和MVC的区别
  9. Vue权限控制——动态注册路由
  10. Linux CentOS6离线安装Jupyter notebook
  11. python多线程调度_python并发编程之进程、线程、协程的调度原理(六)
  12. linux oracle11.2安装 ins-1010,ARCHLINUX下安装oracle11g
  13. AIDL实现不同应用间的通信
  14. Android 10 重磅来袭:支持 5G 与折叠屏、隐私安全全面升级!
  15. go调用python脚本_谁能取代Python?我使用Go来部署机器学习模型的原因
  16. Leetcode-Pascal's Triangle
  17. oracle 基数 选择率,1.1.2.2 可选择率(1)
  18. 常用Win32 API函数
  19. 【已测】开源PHP个人导航网站源码,有后台
  20. 在 Windows Service 服务上部署 AutoVue_EMP_21_0_2 的操作手册

热门文章

  1. apache 各个版本下载
  2. java io流简单笔记
  3. CameraManager——Camera的过时替代方法
  4. 编写一个扑克类(每张扑克有花色和数值,例如红心A,草花10),将52张扑克牌放到集合中(自己去选择集合类)
  5. 【Arduino开源项目】LCR(电感/电容/电阻)电桥测试仪
  6. 操作系统线索-UNIXPC
  7. OC底层原理-Block
  8. CSS之文本框样式和水平居中
  9. WebView手机屏幕(图片适应屏幕的宽度)适配的多种方式
  10. oracle如何查看sequence的值,Oracle sequence详解