jquery - 制作出现在表格行上的响应式弹出窗口单击

标签 jquery html css popup

我正在使用以下代码在每个表格行上制作一个弹出窗口,但我无法将弹出窗口置于屏幕中央,显然它没有响应。

编辑:JSFiddle

HTML:

<table>
   <tbody>
            <tr>
                <th>No.</th>
                <th>Categories</th>
                <th>Sub-Categories</th>
                <th>Counts</th>
                <th>description</th>
            </tr>
            <tr class="popupOpen" data-href="#entry1">
                <td>1</td>
                <td>Category 1</td>
                <td>Sub-Category 1</td>
                <td>12</td>
                <td>This is a test</td>
            </tr>
            <tr>
                <td>2</td>
                <td>Category 2</td>
                <td>Sub-Category 2</td>
                <td>14</td>
                <td>This is a test again</td>
            </tr>
      </tbody>
</table>
<div id="entry1" class="largeWin">
        <a href="#" class="close">X</a>
      <p>some text here...</p>
</div>

JQuery:

$('tr.popupOpen').click(function() {

    var popup= $(this).attr('data-href');

    $(popup).fadeIn(300);

    //Set the center alignment padding + border
    var popMargTop = ($(popup).height() + 24) / 2; 
    var popMargLeft = ($(popup).width() + 24) / 2; 

    $(popup).css({ 
        'margin-top' : -popMargTop,
        'margin-left' : -popMargLeft
    });

    // Add the mask to body
    $('body').append('<div id="mask"></div>');
    $('#mask').fadeIn(300);

    return false;
});

$('a.close, #mask').live('click', function() { 
  $('#mask , .largeWin').fadeOut(300 , function() {
    $('#mask').remove();  
}); 
return false;
});

如何让弹出窗口居中并使其响应?

最佳答案

检查这个 fiddle 。

Updated Fiddle

您是否正在努力实现这样的目标。

$(document).ready(function () {
    $('tr.popupOpen').click(function () {

        var popup = $(this).attr('data-href');

        $(popup).fadeIn(300);

        //Set the center alignment padding + border


        $(popup).css({
            'margin-top': '20px',
                'margin-left': '40px'
        });

        // Add the mask to body
        $('div.container').append('<div id="mask"></div>');
        $('#mask').fadeIn(300);

        return false;
    });

    $('a.close, #mask').live('click', function () {
        $('#mask , .largWin').fadeOut(300, function () {
            $('#mask').remove();
        });
        return false;
    });
});

关于jquery - 制作出现在表格行上的响应式弹出窗口单击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24968756/

相关文章:

javascript - 如何通过 jquery .html 创建 href 并接下来使用它的事件?

javascript - Bootstrap进度条起始值

javascript - 如何检查每个函数内的长度

javascript - req.body 是使用 Express 的简单 HTML 表单的空对象

javascript - 渲染所有可能的元素或根据要求渲染

jquery - CSS 样式被表格打断

javascript - 获取表格单元格失败

javascript - Bootstrap 让文本看起来像按钮

javascript - 将遍历所有 css 文件并将每个 .classname 更改为 .class-name 的脚本

css - 背景图像在除 Firefox 之外的所有浏览器中的错误位置