0

当我单击时,.trigger我希望定位在的对象{left: '0'}向左移动以将相同的像素与浏览器窗口的像素宽度相匹配。有人可以帮我解决这个问题。到目前为止,这是我一起工作的,我无法弄清楚需要追求的功能else.. {left: 'pixel width of browser window'}

$(document).ready(function() {
    // Prompt
    $('.trigger').live('click', toggleName);

    function toggleName() {
        if ($("#some-id").attr('data-state') == 'open') $("#some-id").animate({
            left: '0'
        }, 500, 'easeOutExpo', function() {
            $(this).attr('data-state', 'close')
        }), ;
        else $("#some-id").animate({
            left: 'pixel width of browser window'
        }, 500, 'easeOutExpo', function() {
            $(this).attr('data-state', 'open')
        }), ;
        return false;
    }
});​
4

1 回答 1

1

Use the width function to get the width of the window :

 else $("#some-id").animate({
        left: $(window).width()
 }, ...

This will move the div to the right and let it leave the window (depending on your css).

If you want the div to go stick to the right, you'd better use right: 0 instead.

于 2012-12-01T19:38:39.567 回答