一些别人做的代码,太麻烦太繁琐了,故弄玄虚的封装,目的就是不让别人知道怎么做的,好像很高深似的。本文通过fixed定位,相对浏览器的一种绝对定位,然后用jquery来定义在那个层上的触发事件来实现div的浮动。
floattest.html 就这么几行代码
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script src="jquery-1.7.js" type="text/javascript">
</script>
<script type="text/javascript">
$(document).ready(function()
{
$("#flt").hover(function(){
$("#flt").animate({right:"0px"},300);
},function(){
$("#flt").animate({right:"-150px"},300);
});
});
</script>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="flt">
<table width="100%" height="50" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="50" bgcolor="#990000"> </td>
<td bgcolor="#FFC8C8"> </td>
</tr>
</table>
</div>
<table width="1000" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td height="1000" bgcolor="#0066CC"> </td>
</tr>
</table>
</body>
</html>
style.css 就这么几行
#flt
{
width:200px;
height:50px;
position:fixed;
right:-150px;
top:150px;
}