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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
| <html> <head> <title>提示</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <style> .drag{ width:200px; height:200px; background:rgba(204,255,102,1); position:absolute; cursor:move; top:100px;left:20px; text-align:center; } </style> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script> <script>
$(function () { if(window.localStorage){ $(".drag").css({top:localStorage.getItem("top"),left:localStorage.getItem("left") }); }
var _move = false; var _x, _y; $(".drag").click(function () {
}).mousedown(function (e) { _move = true; _x = e.pageX - parseInt($(".drag").css("left")); _y = e.pageY - parseInt($(".drag").css("top")); $(".drag").fadeTo(20, 0.5); }); $(document).mousemove(function (e) {
if (_move) { var x = e.pageX - _x; var y = e.pageY - _y; $(".drag").css({ top: y, left: x }); window.localStorage.setItem("top",y); window.localStorage.setItem("left",x); } }).mouseup(function () { _move = false; $(".drag").fadeTo("fast", 1); }); }); </script> </head> <body > <div class="drag">O(∩_∩)O哈哈~</div> </body> </html>
|