gpt4 book ai didi

javascript - jquery中的右偏移和下偏移

转载 作者:行者123 更新时间:2023-11-28 01:17:03 25 4
gpt4 key购买 nike

以下代码是来自 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/

最佳答案

var right = ($(window).width() - ($element.offset().left + $element.outerWidth()));

var bottom = $(window).height() - top - link.height();

应该这样做。

关于javascript - jquery中的右偏移和下偏移,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35332912/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com