What does jQuery.offset() method do in jQuery?
例
实时演示
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | <html> <head> jQuery offset() method <script src ="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"> $(document).ready(function() { $("div").click(function () { var offset = $(this).offset(); $("#lresult").html("left offset: <span>" + offset.left +"</span>."); $("#tresult").html("top offset: <span>" + offset.top +"</span>."); }); }); <style> div { width:60px; height:60px; margin:5px; float:left; } </style> </head> <body> <p> Click on any square: </p> <span id ="lresult"> </span> <span id ="tresult"> </span> </body> </html> |