【发布时间】:2012-03-25 18:04:03
【问题描述】:
我正在使用 jQuery 全屏插件https://github.com/martinaglv/jQuery-FullScreen 我的代码:
$('#cancel-fullscreen').hide()
//View Fullscreen
$('#view-fullscreen').click(function(){
$('#container').css({'background': 'green'}).fullScreen();
$(this).hide();
$('#cancel-fullscreen').show();
return false;
});
//Cancel Fullscreen
$('#cancel-fullscreen').click(function(){
//I need this work when "Esc" or "F11" buttons pressed
$('#container').css({'background': 'red'}).fullScreen(); //If press "Esc" background still green..
$(this).hide();
$('#view-fullscreen').show();
return false;
});
效果很好,但我的设计中不需要“取消”按钮,按“Esc”或“F11”按钮可以很好地取消全屏。而且我需要在按下这个按钮后运行一些功能,有什么想法可以做到吗?
谢谢, 库兹。
【问题讨论】:
-
@Lollero 它在全屏模式下不起作用。例如 $(document).keyup(function(e) { if (e.keyCode == 27) {alert('escape') } // esc });如果只是按“Esc”可以工作,但在取消全屏时不起作用!
-
@Lollero 没那么简单 :) 它在 iframe 中运行良好(通过您的链接),但在真实浏览器窗口中无法运行,请尝试使用您的代码 test.xhtml4u.ru/fullscreen/index.html 的实时示例,我认为原因在于HTML5 全屏 API,应该像这样使用: if (document.exitFullscreen) { document.exitFullscreen(); }
-
你可以这样做:忘记我一直在喋喋不休的 esc 代码,并将退出全屏后要执行的代码插入到这一行 github.com/martinaglv/jQuery-FullScreen/blob/master/fullscreen/… 中,如下所示:jsfiddle.net/lollero/mehTv/1 || jsfiddle.net/lollero/mehTv/1/show
标签: jquery html jquery-plugins fullscreen