如何使我的弹出窗口不透明和侧面可拖动?

时间:2012-06-19 11:30:25

标签: javascript jquery html css

我正在创建一个Jquery弹出窗口/对话框,并且我已经将它定位在页面上,只需单击一下,以便div渲染其他元素,但页面是透明的,当我拖动它时,我可以拖动它向上和向下但是当我向侧面拖动时它会调整大小而不是移动。你能告诉我怎样才能解决这两个问题吗?

看起来像这样

enter image description here

我的弹出式HTML是

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>popup</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
</head>
<body>

<table width="100%" border="0" cellspacing="0" cellpadding="2" align="center" class="TB_nb">
  <tr>
  <td colspan="3" class="pusher TB_nb"><h2>Sök person/företag</h2> 
</td>
  <td><a href="javascript:void(0)" onclick="document.getElementById('popupSokNamn').style.display = 'none';" >X</a></td>
</tr>
</table>
<br><br>
<h2 class="pusher">Sök person/företag</h2>
<div id="Vsok">

<div style="text-align: right; width: 100%; padding-right: 5%; padding-top: 5px;">
<span onClick="getElementById('sokF').style.display='', getElementById('bottomA').style.display='none', getElementById('bottomV').style.display='', getElementById('Vsok').style.display='none'" class="link_sm">Visa s&ouml;kformul&auml;r</span>
</div>

</div>

<div id="sokF">

<div style="text-align: right; width: 100%; padding-right: 5%; padding-top: 5px;; padding-bottom: 5px;">
<span onClick="getElementById('sokF').style.display='none', getElementById('bottomA').style.display='none', getElementById('bottomV').style.display='', getElementById('Vsok').style.display=''" class="link_sm">D&ouml;lj s&ouml;kformul&auml;r</span>
</div>

<div style="width: 100%; margin-left: 15px; margin-right: 80px;" class="fontS80">
<fieldset style="border: 1px solid Grey; display:inline;"><legend class="small">Fysisk</legend> 
<div class="fl30">&nbsp;F&ouml;rnamn:</div>
<div class="fl50"><input type="text" size="60" name="searchFornamn" onkeyup="doSubmitByEnter('Namnsokning', 'search')"></div>
<div class="clear"></div>
<div class="fl30">&nbsp;Efternamn:</div>
<div class="fl50"><input type="text" size="60" name="searchEfternamn" onkeyup="doSubmitByEnter('Namnsokning', 'search')"></div>
</fieldset>

<fieldset style="border: 1px solid Grey; display:inline;"><legend class="small">Juridisk</legend> 
<div class="fl30">&nbsp;F&ouml;retag:</div>
<div class="fl50"><input type="text" size="60" name="searchForetag" onkeyup="doSubmitByEnter('Namnsokning', 'search')"></div>
<div class="clear"></div>
<div class="fl30">&nbsp;Organisationsnummer:</div>
<div class="fl50"><input type="text" size="60" name="searchOrgNummer" onkeyup="doSubmitByEnter('Namnsokning', 'search')"></div>
</fieldset> <br><br>

<!-- <div class="fl30">Attention, c/o etc.:</div>
<div class="fl50"><input type="text" size="60"></div>
<div class="clear"></div>

<div class="fl30">Postadress:</div>
<div class="fl50"><input type="text" size="60"></div>
<div class="clear"></div>

<div class="fl30">Postnummer:</div>
<div class="fl50"><input type="text" size="30"></div>
<div class="clear"></div> -->

<div class="fl30">Postort:</div>
<div class="fl50"><input type="text" size="40" name="searchPostort" onkeyup="doSubmitByEnter('Namnsokning', 'search')"></div>
<div class="clear"></div>

<div class="fl30">Land:</div>
<div class="fl50"><input type="text" size="2" name="searchLandKod" onkeyup="doSubmitByEnter('Namnsokning', 'search')">&nbsp;
                    <select name="searchLand" onkeyup="doSubmitByEnter('Namnsokning', 'search')">
                        <option value="1" SELECTED></option>
                        <option value="2"></option>
                        <option value="3"></option>
                        <option value="4"></option>
                        <option value="5">---------------------------------</option>
</select></div>
<div class="clear"></div>

<!-- <div class="fl30">Region:</div>
<div class="fl20"><select name="">
                        <option value="1" SELECTED></option>
                        <option value="2"></option>
                        <option value="3"></option>
                        <option value="4"></option>
                        <option value="5">-----------------------------------------------</option>
</select></div>
<div class="clear"></div>
<div class="fl30">Tel:</div>
<div class="fl50"><input type="text" size="40"></div>
<div class="clear"></div>

<div class="fl30">Fax:</div>
<div class="fl50"><input type="text" size="40"></div>
<div class="clear"></div>

<div class="fl30">E-post:</div>
<div class="fl50"><input type="text" size="60"></div>
<div class="clear"></div>
 -->
<div class="fl50">&nbsp;</div>
<div class="fl5"><input type="button" value="Rensa"></div>
<div class="fl10"><input type="button" value="  S&ouml;k  " onclick="javascript:doSubmit('Namnsokning', 'search')"></div>
<div class="clear">&nbsp;</div>
<div class="clear">&nbsp;</div>
</div>

</div>

<table width="100%" border="0" cellspacing="0" cellpadding="4" align="center">
<tr>    
    <td><h3>Sökresultat:</h3></td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
</tr>
<tr>    
    <td colspan="4">En massa text <span class="link">Hj&auml;lp!</span> </td>
</tr>
<tr>    
    <td><input type="button" value="Visa alla"></td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
</tr>
<tr class="smallb">
    <td>Antal &auml;renden: 527</td>
    <td>&nbsp;</td>
    <td>Visa &auml;renden: &#60;&#60; 1-200 201-400 401-527 &#62;&#62; </td>
<td>&nbsp;</td>
</tr>
</table>

<table width="100%" cellspacing="0" align="center" class="sortable" id="unique_id">
<tr>
    <th class="thkant">F&ouml;rnamn</th>
    <th class="thkant">Efternamn</th>
    <th class="thkant">Adress</th>
    <th class="thkant">Postnr</th>
    <th class="thkant">Postort</th>
    <th class="thkant">Region</th>
    <th class="thkant">Land</th>
    <th class="thkant">Telefonnummer</th>
</tr>


</table>


<div id="bottomV">
<table width="100%" align="center">
<tr>
<td align="left"><input type="button" id="visaknapp" value="Visa" disabled style="width:150px;" onClick="getElementById('sokR').style.display='', getElementById('bottomA').style.display='', getElementById('bottomV').style.display='none', getElementById('Vsok').style.display='', getElementById('sokF').style.display='none'"></td>
<td align="right"><input type="button" value="Avbryt" style="width:150px;" class="checkmargin"><input type="button" value="Infoga" disabled style="width:150px;"></td>
</tr>
</table>
</div>

<div id="bottomA" style="display: none">
<table width="100%" align="center">
<tr>
<td align="left"><input type="button" value="&Auml;ndra i register" style="width:150px;"></td>
<td align="right"><input type="button" value="Avbryt" style="width:150px;" class="checkmargin"><input type="button" value="Infoga" style="width:150px;"></td>
</tr>
</table>

</body>
</html>

CSS

.newpopup {
  position: absolute; 
  top:50%;
  left:50%;
} 

Javascript是

function popup() {
    alert('test');
    var popup = $('.newpopup');
    popup.draggable();
    popup.resizable();
    //popup.html('<p>Where is pancakes house?</p>');
    //popup.show('fast');

       $.get('/PandoraArendeWeb/popup.jsp', function(data) {   

        popup.html(data); 
        popup.show('fast'); 
    }); 

    var screen_width = $(document).width();
var screen_height = $(document).height();
var box_width = popup.width();
var box_height = popup.height();

var top = (screen_height - box_height) / 2; // you might like to subtract a little to position it slightly higher than half way
var left = (screen_width - box_width) / 2;
    popup.css({ 'position': 'absolute', 'top':top, 'left':left });
}
$(document).ready(function(){
  $('button').click(function(){
     popup();
  });
})

请告诉我如何

1)使弹出窗口不透明 2)使弹出侧面可拖动

实际激活弹出窗口的HTML很简单:

<div class='newpopup'>
</div>
<button>popup</button>

谢谢

1 个答案:

答案 0 :(得分:3)

好吧我使用jsfiddle here创建了简单的测试用例,我不认为你的jquery有什么问题,但我相信它是ajax调用所以在你的服务器上测试它以确保你的ajax调用工作(因为我不能),如果你的ajax调用失败,它将不会弹出。在测试用例中,它会警告&#34;错误&#34;。

HTML:

<button>popup</button>
<div class='newpopup'>
</div>

jQuery的:

function popup() {
    alert('opening popup');
    var popup = $('.newpopup');
    popup.draggable();
    popup.resizable();
    //popup.html('<p>Where is pancakes house?</p>');
    //popup.show('fast');

    //Comment me out and use the version below to show working
    $.ajax({url:'/PandoraArendeWeb/popup.jsp',
            error: function() {
                alert('Error');
            },
            success: function(data) {   
                popup.html("test"); 
                popup.show('fast');
            }
       }
   ); 


   /*
    popup.html("test"); 
    popup.show('fast');
    */
    var screen_width = $(document).width();
var screen_height = $(document).height();
var box_width = popup.width();
var box_height = popup.height();

var top = (screen_height - box_height) / 2; // you might like to subtract a little to position it slightly higher than half way
var left = (screen_width - box_width) / 2;
    popup.css({ 'position': 'absolute', 'top':top, 'left':left });
}
$(document).ready(function(){
  $('button').click(function(){
     popup();
  });
})​

CSS:

.newpopup {
  position: absolute; 
  top:50%;
  left:50%;
  background-color:#ff0; //Yellow
} ​

修改 记得尝试评论ajax并使用下面的位。弹出窗口显示,您可以拖动它:)