js 随机数抓蚊子
来源:互联网 发布:阿里云短信群发接口 编辑:程序博客网 时间:2024/05/16 12:10
<script type="text/javascript">
window.onload = function(){
// 抓取元素
var img = document.getElementById("img");
// 获得可视区域的宽度和高度
var width = document.documentElement.clientWidth;
var height = document.documentElement.clientHeight;
// 添加鼠标移入事件
img.onmouseover = function(){
// 获得top值的随机数
var top = Math.floor(Math.random()*(height-100-0+1)+0);
// 获得left值的随机数
var left = Math.floor(Math.random()*(width-100-0+1)+0);
// 修改top值和left值
img.style.top = top+'px';
img.style.left = left+'px';
}
}
window.onload = function(){
// 抓取元素
var img = document.getElementById("img");
// 获得可视区域的宽度和高度
var width = document.documentElement.clientWidth;
var height = document.documentElement.clientHeight;
// 添加鼠标移入事件
img.onmouseover = function(){
// 获得top值的随机数
var top = Math.floor(Math.random()*(height-100-0+1)+0);
// 获得left值的随机数
var left = Math.floor(Math.random()*(width-100-0+1)+0);
// 修改top值和left值
img.style.top = top+'px';
img.style.left = left+'px';
}
}
</script>
///////////////html/////////
<img id="img" src="img/wenzi.jpg" style="top: 0px; left: 0px;"/>
////////css///////////
<style type="text/css">
#img{
position: absolute;
width: 100px;
}
</style>
阅读全文
0 0
- js 随机数抓蚊子
- 蚊子
- 蚊子
- 蚊子
- js随机数
- js随机数
- JS随机数
- JS随机数
- js 随机数
- 蚊子,可恶的蚊子
- JS创建随机数
- js生成随机数
- js生成随机数
- JS实现随机数
- JS创建随机数
- js生成随机数
- JS随机数的函数
- JS产生随机数
- oracle 存储过程 判断字段中是否包含指定的字符
- Activity启动过程
- SeaweedFS索引-CompactMap
- PyQt-1
- MyBatis获取自增ID
- js 随机数抓蚊子
- 安卓架构师之路
- 上拉跳转界面,仿淘宝
- 工作感悟
- 连接mysql数据库的配置备忘
- 字符串查找—练习一
- C# 窗体操作汇总
- java.exe和javaw.exe有什么区别?
- AIDL