div跟随鼠标移动代码。不需要jquery,div自动调整div到页面的右边后到左边来,鼠标到下面时到div到上面,支持滚动条移动哪位大虾有这样的代码。我找了好久没找到。包括找了国外的网站
解决方案 »
- Struts2 在拦截器中想重新定向跳转地址,如何实现
- java.io.InvalidClassException什么错误
- Struts2中向Action提交值时,验证拦截器总是提示值无效并返回input页面。。。
- ajax 怎么读音呢?有标准吗?
- tomcat启动问题
- 有人用过jasper report么,在netbean中,看了一个文档,有些疑问
- 求助:struts ,list 问题,帮我!!!
- 求portal资料或教程
- 如何在HTML页上嵌入式调用VC做的COM组件(OCX、DLL)控件
- 分儿多多!jsp调用javabean老是报Unclosed jsp:useBean tag错误!
- jsp里用img标签如何访问本地的图片啊
- 程序运行报错,高手请支招.
看了好几遍也没看懂这 句
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head><body>
<div style="background-color:#00CC00; width:100px; height:100px; position:absolute; left:225px; top:80px;" id="div1"></div>
</body>
</html>
<script>
var m_x;
var m_y;
var div_=document.getElementById("div1").style;
var id1;
var id2;
document.onmousemove=function()
{
m_x=event.x;
m_y=event.y;
move();
}
function move()
{
if(parseInt(div_.left)>parseInt(m_x))
{
if(id1==null)
id1=setInterval(div_move_left,10);
}
else
{
if(id1==null)
id1=setInterval(div_move_right,10);
}
if(parseInt(div_.top)>parseInt(m_y))
{
if(id2==null)
id2=setInterval(div_move_top,10);
}
else
{
if(id2==null)
id2=setInterval(div_move_bottom,10);
}
}
function div_move_left()
{
div_.left=parseInt(div_.left)-2;
if(parseInt(div_.left)<parseInt(m_x))
{
clearInterval(id1);
id1=null;
}
}
function div_move_right()
{
div_.left=parseInt(div_.left)+2;
if(parseInt(div_.left)>parseInt(m_x))
{
clearInterval(id1);
id1=null;
}
}
function div_move_top()
{
div_.top=parseInt(div_.top)-2;
if(parseInt(div_.top)<parseInt(m_y))
{
clearInterval(id2);
id2=null;
}
}
function div_move_bottom()
{
div_.top=parseInt(div_.top)+2;
if(parseInt(div_.top)>parseInt(m_y))
{
clearInterval(id2);
id2=null;
}
}
</script>