【问题标题】:Offset Right and Bottom in jquery在jquery中向右和底部偏移
【发布时间】:2016-02-11 07:11:22
【问题描述】:

以下代码是来自 w3schools 的示例。

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $("button").click(function(){
        var x = $("p").offset();
        alert("Top: " + x.top + " Left: " + x.left);
    });
});
</script>
</head>
<body>

<p>This is a paragraph.</p>

<button>Return the offset coordinates of the p element</button>

</body>
</html>

是否可以使用jquery获得右偏移和偏移底部?

链接:

https://jsfiddle.net/0hhxdbk5/1/

【问题讨论】:

    标签: javascript jquery html positioning offset


    【解决方案1】:
    var right = ($(window).width() - ($element.offset().left + $element.outerWidth()));
    
    var bottom = $(window).height() - top - link.height();
    

    应该这样做。

    【讨论】:

    • 抱歉,链接是:var link = $(element);
    • 谢谢你,top是指偏移top?
    猜你喜欢
    • 2022-01-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-08
    • 1970-01-01
    • 1970-01-01
    • 2019-03-20
    相关资源
    最近更新 更多