JS实现文字复制时弹出层
时间:2015-05-28 阅读:次 QQ群:182913345
该段JS代码能够实现,当用户复制网页文字时,自动弹出预先自定义好的弹出层信息。演示代码如下:
<html> <head> <script src="http://www.php520.cn/templets/default/js/jquery-1.8.3.min.js"></script> </head> <body> <style> .tooltip{width:147px;hiehgt:30px;} </style> <script> $(function(){ $(".content").mouseup(function (e) { var x = 10; var y = 10; var r = ""; if (document.selection) { r = document.selection.createRange().text; } else if (window.getSelection()) { r = window.getSelection(); } if (r!= "") { var bowen = " "; var tooltip = "<div id='tooltip' class='tooltip'>弹出层</div>"; $("body").append(tooltip); $("#tooltip").css({ "top": (e.pageY + y) + "px", "left": (e.pageX + x) + "px", "position": "absolute" }).show("fast"); } }).mousedown(function () { $("#tooltip").remove(); }); }) </script> <div class="content">php技术分享</div> </body> </html> |