如何使弹出框出现在身体顶部而不是身体上方

时间:2014-12-31 06:35:47

标签: javascript jquery html

主页上显示一个弹出框。但问题是,无论我放在模板中的什么位置,它都显示在正文或标题上方。但是我希望它以transparents为背景显示,覆盖内容。看看弹出框如何正常工作。但我该如何实现呢?

home.tpl(这是我放置弹出框的地方)

<!DOCTYPE html>
<html class="no-js" lang="en">
<head>
<?php include($data['config']['THEME_DIR_INC'].'inc/meta_common.inc.php'); ?>
<title>
<?php include($data['config']['THEME_DIR_INC'].'inc/title.inc.php'); ?>
</title>
<?php include($data['config']['THEME_DIR_INC'].'inc/scripts_common.inc.php'); ?>
</head>
<body>

<div id="wrapper">
  <?php include($data['config']['THEME_DIR_INC'].'inc/header.inc.php'); ?>
  <?php #include($data['config']['THEME_DIR_INC'].'inc/nav_main.inc.php'); ?>
     <div id="position_scroll">

      </div>
    <div id="boxes">
 <?php include($data['config']['THEME_DIR_INC'].'inc/promo.inc.php'); ?> 
    </div>
  <div id="main">
    <?php require($this->view_location); ?>

  </div>
  <?php include($data['config']['THEME_DIR_INC'].'inc/footer.inc.php'); ?>
</div>
</body>
</html>

脚本

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.js"></script>
<script type="text/javascript">
    var jpop=$.noConflict(true);
jpop(document).ready(function() {   

        var id = '#dialog';

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

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

        //transition effect     
        jpop('#mask').fadeIn(1000); 
        jpop('#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
        jpop(id).css('top',  winH/2-$(id).height()/2);
        jpop(id).css('left', winW/2-$(id).width()/2);

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

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

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

    //if mask is clicked
    jpop('#mask').click(function () {
        jpop(this).hide();
        jpop('.window').hide();
    });     

});

</script>

1 个答案:

答案 0 :(得分:0)

你必须将css添加到你的盒子div

div#boxes{
    position:fixed;
    z-index: 99; /* so that the div stays on top of others */
    top: 50px; /* distance from the top */
    height: 400px; /*set as neccessary */
    width: 400px;  /*set as neccessary */

    /* To center the box */
    margin-left: auto;
    margin-right: auto;
}