javascript每日一练(六)——事件一
一、event对象
var oEvent = ev || event;//获取事件对象 oEvent.clientX oEvent.clientY//获取鼠标坐标 oEvent.cancelBubble = true;//阻止冒泡
<!doctype html> <html> <head> <meta charset="utf-8"> <title>无标题文档</title> <style> #div1{ width:100px; height:100px; background:red; display:none; position:absolute;} </style> <script> window.onload = function(){ var oBtn = document.getElementById('btn1'); var oDiv = document.getElementById('div1'); //event对象,用来获取事件的详细信息 //获取鼠标位置 document.onmousemove = function(ev){ var oEvent = ev || event; var scrollTop = document.documentElement.scrollTop || document.body.scrollTop; oDiv.style.top = oEvent.clientY + scrollTop + 'px'; oDiv.style.left = oEvent.clientX + 'px'; }; oBtn.onclick = function(ev){ var oEvent = ev || event; oDiv.style.display = 'block'; oEvent.cancelBubble = true; }; document.onclick = function(){ oDiv.style.display = 'none'; }; }; </script> </head> <body style="height:2000px;"> <input id="btn1" type="button" value="显示" /> <div id="div1"> <a href="http://baidu.com">百度</a> </div> </body> </html>
javascript每日一练(六)——事件一的更多相关文章
- javascript每日一练(七)——事件二:键盘事件
一.键盘事件 onkeydown触发, keyCode键盘编码 ctrlKey altKey shiftKey 键盘控制div移动 <!doctype html> <html> ...
- javascript每日一练(八)——事件三:默认行为
一.阻止默认行为 return false; 自定义右键菜单 <!doctype html> <html> <head> <meta charset=&quo ...
- javascript每日一练(一)——javascript基础
一.javascript的组成 ECMAScript DOM BOM 二.变量类型 常见类型有:number, string, boolean, undefined, object, function ...
- javascript每日一练—运动
1.弹性运动 运动原理:加速运动+减速运动+摩擦运动: <!doctype html> <html> <head> <meta charset="u ...
- javascript每日一练(十四)——弹性运动
一.弹性运动 运动原理:加速运动+减速运动+摩擦运动: <!doctype html> <html> <head> <meta charset="u ...
- javascript每日一练(十三)——运动实例
一.图片放大缩小 <!doctype html> <html> <head> <meta charset="utf-8"> < ...
- javascript每日一练(十二)——运动框架
运动框架 可以实现多物体任意值运动 例子: <!doctype html> <html> <head> <meta charset="utf-8&q ...
- javascript每日一练(十一)——多物体运动
一.多物体运动 需要注意:每个运动物体的定时器作为物体的属性独立出来互不影响,属性与运动对象绑定,不能公用: 例子1: <!doctype html> <html> <h ...
- javascript每日一练(十)——运动二:缓冲运动
一.缓冲运动 实现原理:(目标距离-当前距离) / 基数 = 速度(运动距离越大速度越小,运动距离和速度成反比) (500 - oDiv.offsetLeft) / 7 = iSpeed; 需要注意: ...
随机推荐
- How to Programmatically Add/Delete Custom Options in Magento? - See more at: http://apptha.com/blog/
In this tutorial, I would like to help out Magento developers and clients with how to programmatical ...
- Aspx 页面生命周期
ASP.NET 页运行时,此页将经历一个生命周期,在生命周期中将执行一系列处理步骤.这些步骤包括初始化.实例化控件.还原和维护状态.运行事件处理程序代码以及进行 呈现.了解页的生命周期非常重要,这样就 ...
- Swift和OC 混编
1.首先创建一个Swift工程 2.导入或者创建一个OC文件(.h和.m) 3.再创建一个桥连接文件 4.然后文件样子为 5.在桥接链接里面导入头文件 6.通过targets->->bui ...
- ZOJ 1093 Monkey and Banana (LIS)解题报告
ZOJ 1093 Monkey and Banana (LIS)解题报告 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid= ...
- 杭电oj An easy problem
</pre><h1 style="color: rgb(26, 92, 200);">An easy problem</h1><stron ...
- 条款05:了解C++默默编写并调用哪些函数
每一个class都会有一个或多个构造函数.一个析构函数.一个copy assignment操作符.这些控制着基础操作,像是产出新对象并确保它被初始化.摆脱旧对象并确保它被适当清理.以及赋予对象新值. ...
- Python之路:Python 基础(三)-文件操作
操作文件时,一般需要经历如下步骤: 打开文件 操作文件 一.打开文件 文件句柄 = file('文件路径', '模式') # 还有一种方法open 例1.创建文件 f = file('myfile. ...
- poj 2309
http://poj.org/problem?id=2309//找规律 可以看到每个根节点都可以将其在同一层的最左边的根节点整除,并且最大值为该节点加上最左边的节点值-1,最小值为////为该节点减去 ...
- 转: sublime text 2 前端编码神器-快捷键与使用技巧介绍
代码编辑器或者文本编辑器,对于程序员来说,就像剑与战士一样,谁都想拥有一把可以随心驾驭且锋利无比的宝剑,而每一位程序员,同样会去追求最适合自己的强大.灵活的编辑器,相信你和我一样,都不会例外. 如果说 ...
- QT 遍历目录查找指定文件(比较简单)
QString FindFile(const QString &strFilePath, const QString &strNameFilters){ if (strFilePath ...