使用jquery增加或减少偏移量

时间:2013-10-30 10:54:22

标签: jquery html css

我有一个弹出窗口。我希望弹出窗口上有两个加号和减号按钮。点击的两个按钮应该能够改变弹出窗口的偏移量。我的问题可能不成熟,但我是jquery的新手所以我无法处理这个场景。如何使按钮工作。

 <div class="button" id="show">
    <button type="button">Show popup</button>
</div>


<div class="container-popup" id="container-popup">
<div>
    <button type="button" id="plus">Increase</button>
    <button type="button" id="minus">Decrease</button>
</div>
    <div class="pop-up" id="pop-up">
        <div class="circleBase type2" id="close">x</div>
        <p>It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English.</p>
    <p>Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).</p>
    <p>Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).</p>
    </div>
</div>

这是我的JSFIDDLE

1 个答案:

答案 0 :(得分:3)

$("#plus").click(function(){
        var x=$("#pop-up").offset();
        $("#pop-up").offset({top : x.top + 5, left : x.left + 5});      
});

设置弹出元素的偏移量。查看fiddle