<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> New Document </title> <script src="styles/default/js/jquery-2.1.0.min.js"></script> </head> <style type="text/css"> .modle { width: 100px; cursor: pointer; text-align: center; } #popmenu { display: none; position: absolute; width: 100px; height: 100px; margin-top: 10px; margin-left: 10px; border: 1px solid black; background-color: white } </style> <body> <div class="modle"> click me </div> <div id="popmenu"> 内容 </div> </body> <script type="text/javascript"> var menu = document.getElementById("popmenu"); $(".modle").click(function(event) { e = event ? event : window.event; t = e.target || e.srcElement; menu.style.left = getPointerX(e) + "px"; menu.style.top = getPointerY(e) + "px"; menu.style.display = "block"; }); function getPointerX(event) { return event.pageX || (event.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft)); } function getPointerY(event) { return event.pageY || (event.clientY + (document.documentElement.scrollTop || document.body.scrollTop)); } </script> </html>
原创文章,作者:Maggie-Hunter,如若转载,请注明出处:https://blog.ytso.com/8677.html