Javascript 用于弹出web屏幕的jQuery Lightbox/Modal窗口

Javascript 用于弹出web屏幕的jQuery Lightbox/Modal窗口,javascript,jquery,Javascript,Jquery,在我的web应用程序中,我正在考虑创建一个页面的弹出屏幕,供用户进行一些处理 我基本上希望这个页面像一个向下钻取的窗口,根据您从顶级摘要记录中按下的按钮显示详细的REORD 我考虑的不是弹出窗口,而是jQuery lightbox特性/模式窗口 我愿意提供建议和灯箱的简单示例,用于显示web屏幕,而不是照片,几乎是一个弹出窗口,但具有jQuery外观,即放大到用户,然后再缩小到摘要记录。试试这个示例 <html xmlns="http://www.w3.org/1999/xhtml">

在我的web应用程序中,我正在考虑创建一个页面的弹出屏幕,供用户进行一些处理

我基本上希望这个页面像一个向下钻取的窗口,根据您从顶级摘要记录中按下的按钮显示详细的REORD

我考虑的不是弹出窗口,而是jQuery lightbox特性/模式窗口

我愿意提供建议和灯箱的简单示例,用于显示web屏幕,而不是照片,几乎是一个弹出窗口,但具有jQuery外观,即放大到用户,然后再缩小到摘要记录。

试试这个示例

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Simple JQuery Modal Window from Queness</title>

<script type="text/javascript" src="http://code.jquery.com/jquery-latest.pack.js"></script>
<script>

$(document).ready(function() {  

    //select all the a tag with name equal to modal
    $('a[name=modal]').click(function(e) {
        //Cancel the link behavior
        e.preventDefault();

        //Get the A tag
        var id = $(this).attr('href');

        //Get the screen height and width
        var maskHeight = $(document).height();
        var maskWidth = $(window).width();

        //Set heigth and width to mask to fill up the whole screen
        $('#mask').css({'width':maskWidth,'height':maskHeight});

        //transition effect     
        $('#mask').fadeIn(1000);    
        $('#mask').fadeTo("slow",0.8);  

        //Get the window height and width
        var winH = $(window).height();
        var winW = $(window).width();

        //Set the popup window to center
        $(id).css('top',  winH/2-$(id).height()/2);
        $(id).css('left', winW/2-$(id).width()/2);

        //transition effect
        $(id).fadeIn(2000); 

    });

    //if close button is clicked
    $('.window .close').click(function (e) {
        //Cancel the link behavior
        e.preventDefault();

        $('#mask').hide();
        $('.window').hide();
    });             

});

</script>
<style>
body {
font-family:verdana;
font-size:15px;
}

a {color:#333; text-decoration:none}
a:hover {color:#ccc; text-decoration:none}

#mask {
  position:absolute;
  left:0;
  top:0;
  z-index:9000;
  background-color:#000;
  display:none;
}

#boxes .window {
  position:absolute;
  left:0;
  top:0;
  width:440px;
  height:200px;
  display:none;
  z-index:9999;
  padding:20px;
}

#boxes #dialog {
  width:375px; 
  height:203px;
  padding:10px;
  background-color:#ffffff;
}

</style>
</head>
<body>
<h2>Simple jQuery Modal Window</h2>
<ul>
<li><a href="#dialog" name="modal">Simple Window Modal</a></li>
</ul>

<div id="boxes">
<div id="dialog" class="window">
Simple Modal Window | 
<a href="#"class="close"/>Close it</a>
<p>Anything can go Here</p>
</div>
<!-- Mask to cover the whole screen -->
  <div id="mask"></div>
</div>

</body>
</html>

您确定该屏幕需要是模态的吗?在他们可以使用应用程序的其余部分之前,他们在该屏幕上所做的是必不可少的吗


否则,不恰当地引入模态窗口可能会损害可用性。尝试扩大面积,而不是使用灯箱技术。

谢谢Tony。根据您的示例,是否可以通过传递url作为源来将其用作iframe模式窗口?另外,“Esc”键也可以用来关闭模式窗口吗?从未用Iframe尝试过,但我不明白为什么它不起作用。或者可以使用Jquery将另一个文件中的代码插入模式的div标记中