javascript - 如何使我的弹出窗口不透明且可横向拖动?

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

谢谢

最佳答案

好的,我使用 jsfiddle 创建了简单的测试用例 here ,我认为您的 jquery 没有任何问题,但我相信它是 ajax 调用,因此要在您的服务器上测试它以确保您的 ajax 调用正常工作(因为我不能),如果您的 ajax 调用失败,它将不会弹出。在测试用例中,它将警告“错误”。

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 并使用下面的位。弹出窗口显示,您可以拖动它:)

关于javascript - 如何使我的弹出窗口不透明且可横向拖动?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11100022/

相关文章:

html - HTML5 页脚元素内的链接(导航和旁边?)

javascript - jquery复选框无法点击

php - 使用来自 MySQL 的图像 URL 显示图像

javascript - JSON.parse(hr.response) 错误

javascript - jQuery:如何从逗号分隔的字符串创建索引数组

javascript - jQuery获取child的值并设置输入框的值

javascript - 更改状态栏中的链接

javascript - onclick 函数在 JavaScript 中不起作用

Javascript 模块声明 - 性能

javascript - jquery superbox 库不工作