<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title> <style> *{ margin:0; padding:0;} #login{ border:1px #000 solid; position:absolute; padding:20px } #close{ position:absolute; right:0; top:0;} </style> <script src="http://libs.baidu.com/jquery/1.9.0/jquery.js" type="text/javascript"></script> <script> $(function(){ $(‘#input1‘).click(function(){ var oLogin = $(‘<div id="login"><p>用户名:<input type="text" /></p><p>密码:<input type="text" /></p><div id="close">X</div></div>‘); $(‘body‘).append( oLogin ); oLogin.css(‘left‘ , ($(window).width() - oLogin.outerWidth())/2 ); oLogin.css(‘top‘ , ($(window).height() - oLogin.outerHeight())/2 ); $(‘#close‘).click(function(){ oLogin.remove(); }); $(window).on(‘resize scroll‘,function(){ oLogin.css(‘left‘ , ($(window).width() - oLogin.outerWidth())/2 ); oLogin.css(‘top‘ , ($(window).height() - oLogin.outerHeight())/2 + $(window).scrollTop() ); }); }); }); </script> </head> <body style="height:2000px;"> <input type="button" value="点击" id="input1" /> <!--<div id="login"> <p>用户名:<input type="text" /></p> <p>密码:<input type="text" /></p> <div id="close">X</div> </div>--> </body> </html>
时间: 2024-10-09 23:13:13