2016-02-11 51 views
2

以下代碼是w3schools中的一個示例。jquery中的右下角偏移

<!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/

回答

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

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

這應該這樣做。

+1

什麼是鏈接 – Venkat

+0

對不起,鏈接將是:var link = $(element); –

+1

謝謝你,頂部意味着抵消頂部? – Venkat