用于弹出Web屏幕的jQuery Lightbox / Modal Windows

时间:2009-07-01 11:24:24

标签: javascript jquery

在我的网络应用程序中,我正在考虑为用户创建一个页面的弹出屏幕,以便进行一些处理。

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

而不是弹出窗口,我在想一个jQuery灯箱功能/模态窗口。

我愿意接受建议以及用于显示网页而不是照片的灯箱的简单示例,几乎是一个弹出窗口,但具有jQuery的外观和感觉,即放大到用户的东西然后缩放回到摘要记录。

希望有人可以提供示例/网址等帮助。

感谢。 贝。

3 个答案:

答案 0 :(得分:3)

试试这个例子,

<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>

答案 1 :(得分:1)

http://jquery.com/demo/thickbox/

Thickbox在灯箱式模式中实现内联内容。

答案 2 :(得分:-1)

你确定你的屏幕需要模态吗?在他们使用应用程序的其余部分之前,他们在该屏幕上所做的事情对他们来说至关重要吗?

如果不是,您可能会通过不恰当地引入模态窗口来损害可用性。尝试扩大区域而不是使用灯箱技术。

相关问题