JS实现的鼠标跟随代码(卡通手型点击效果)
2015-10-26 11:10
991 查看
本文实例讲述了JS实现带有小手点击效果的鼠标跟随代码。分享给大家供大家参考,具体如下:
一个跟随鼠标的小手效果,鼠标移在哪里,小手就跟着移向哪里,会出现手的效果,放在链接上的时候,手会变化,两只手很可爱哦,JS鼠标跟随代码分享与大家。
运行效果截图如下:
在线演示地址如下:
http://demo.jb51.net/js/2015/js-handle-style-focus-codes/
具体代码如下:
<!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> html{ background:#000;} body,html,input{ cursor:none;} body,html{ height:100%;} #cursor{ position:absolute; left:100px; top:100px; display:block;} </style> <script> window.onload = function(){ var oCursor = document.getElementById("cursor"); document.onmousemove=function (ev){ var oEvent=ev||event, oWidth = document.documentElement.clientWidth, oHeight = document.documentElement.clientHeight, scrollTop=document.documentElement.scrollTop + oEvent.clientY, scrollLeft=document.documentElement.scrollLeft + oEvent.clientX; if(scrollTop > oHeight-oCursor.offsetHeight){ oCursor.style.top = oHeight-oCursor.offsetHeight+'px'; }else if(scrollTop < 0){ oCursor.style.top = 0; }else{ oCursor.style.top = scrollTop+'px'; } if(scrollLeft > oWidth-oCursor.offsetWidth){ oCursor.style.left = oWidth-oCursor.offsetWidth+'px'; }else{ oCursor.style.left = scrollLeft+'px'; } document.onmousedown = function(){ oCursor.innerHTML = "<img src='images/cursor_hover.png' />"; return false; } document.onmouseup = function(){ oCursor.innerHTML = "<img src='images/cursor.png' />"; } }; } </script> </head> <body> <div id="cursor"><img src="images/cursor.png" /></div> <input type="button" style="font-size:36px; margin:100px;" value="点击" onclick="window.open('http://www.baidu.com')" /> </body> </html>
希望本文所述对大家JavaScript程序设计有所帮助。
您可能感兴趣的文章:
相关文章推荐
- Extjs4.0 最新最全视频教程
- Javascript中toFixed方法的改进
- 5个常见可用性错误和解决方案
- 微软无线镭射简报鲨8000激光笔记本鼠标 - (2)
- 鼠标与“助手”的不解之缘
- js可突破windows弹退效果代码
- Delphi实现窗体感知鼠标滑过并自动隐藏与显示窗口的方法
- JSP脚本漏洞面面观
- 使用BAT一句话命令实现快速合并JS、CSS
- js显示当前星期的起止日期的脚本
- 爆炸式的JS圆形浮动菜单特效代码
- C#模拟window操作鼠标的方法
- js select常用操作控制代码
- JS实现不使用图片仿Windows右键菜单效果代码
- 从jsp发送动态图像
- 原生js结合html5制作小飞龙的简易跳球
- js 页面模块自由拖动实例
- js实现小鱼吐泡泡在页面游动特效
- js 提交和设置表单的值
- PHP VBS JS 函数 对照表