如何让div全屏显示?
我正在使用 Flot 来绘制我的一些数据,我认为这会很棒单击按钮后使该图全屏显示(占据显示器上的全部空间)。目前,我的div
如下:
<div id="placeholder" style="width:800px;height:600px"></div>
当然,style属性仅用于测试。在实际设计过程中,我会将其移至 CSS
中。无论如何,我可以让这个 div 全屏显示并仍然保留所有事件处理吗?
I am using Flot to graph some of my data and I was thinking it would be great to make this graph appear fullscreen (occupy full space on the monitor) upon clicking on a button. Currently, my div
is as follows:
<div id="placeholder" style="width:800px;height:600px"></div>
Of course, the style attribute is only for testing. I will move this to CSS
after during the actual design. Is there anyway I could make this div fullscreen and still preserve all event handling?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(11)
您可以使用 HTML5 Fullscreen API 来实现此目的(这是我认为最合适的方式)。
全屏必须通过用户事件(单击、按键)触发,否则将无法工作。
这是一个按钮,单击后会使 div 全屏显示。在全屏模式下,单击按钮将退出全屏模式。
另请注意,Chrome 的全屏 API 不适用于非安全页面。请参阅 https请访问://sites.google.com/a/chromium.org/dev/Home/chromium-security/deprecating-powerful-features-on-insecure-origins了解更多详情。
另一件需要注意的是 :fullscreen CSS 选择器。您可以将其附加到任何 css 选择器,以便在该元素全屏显示时应用规则:
You can use HTML5 Fullscreen API for this (which is the most suitable way i think).
The fullscreen has to be triggered via a user event (click, keypress) otherwise it won't work.
Here is a button which makes the div fullscreen on click. And in fullscreen mode, the button click will exit fullscreen mode.
Please also note that Fullscreen API for Chrome does not work in non-secure pages. See https://sites.google.com/a/chromium.org/dev/Home/chromium-security/deprecating-powerful-features-on-insecure-origins for more details.
Another thing to note is the :fullscreen CSS selector. You can append this to any css selector so that the rules will be applied when that element is fullscreen:
当您说“全屏”时,您是指计算机的全屏,还是占用浏览器中的整个空间?
您不能强制用户进入全屏
F11
;但是,您可以使用以下 CSS 使您的 div 全屏显示。这当然会假设您的 div 是
标记的子级。否则,除了上述代码之外,您还需要添加以下内容。
When you say "full-screen", do you mean like full-screen for the computer, or for taking up the entire space in the browser?
You can't force the user into full-screen
F11
; however, you can make your div full screen by using the following CSSThis will of course assume your div is child of the
<body>
tag. Otherwise, you'd need to add the following in addition to the above code.CSS方式:
JS方式:
CSS way:
JS way:
对于全屏浏览器渲染区域,有一个所有现代浏览器都支持的简单解决方案。
唯一值得注意的例外是 Android 4.3 以下 - 但 ofc 仅在系统浏览器/webview 元素中(Chrome 工作正常)。
浏览器支持图表:http://caniuse.com/viewport-units
对于显示器的全屏,请使用 HTML5 全屏应用程序编程接口
For fullscreen of browser rendering area there is a simple solution supported by all modern browsers.
The only notable exception is the Android below 4.3 - but ofc only in the system browser/webview element (Chrome works ok).
Browser support chart: http://caniuse.com/viewport-units
For fullscreen of monitor please use HTML5 Fullscreen API
一样使用 FullScreen API
可以像这个Demo
PS:现在使用 screenfull.js 。一个简单的包装器,用于 JavaScript 全屏 API 的跨浏览器使用。
Can use FullScreen API like this
Demo
P.S: Using screenfull.js nowadays. A simple wrapper for cross-browser usage of the JavaScript Fullscreen API.
这是最简单的一个。
This is the simplest one.
你可以尝试这个..
宽度和高度取决于你的flot或图表..
希望你想要这个...
或者
通过点击,你可以通过jquery使用它
u can try this..
width and height depends on your flot or graph..
hope u want this...
or
By clicking, u can use this by jquery
如果您想将其显示在浏览器的可见区域(可滚动区域)之外,请使用文档高度。
CSS 部分
JQuery 部分
Use document height if you want to show it beyond the visible area of browser(scrollable area).
CSS Portion
JQuery Portion
有了 Bootstrap 5.0,现在这变得非常简单。只需在全屏元素上打开和关闭这些类即可。
With Bootstrap 5.0 this is incredibly easy now. Just toggle these classes on and off the full screen element.