js根据鼠标移动速度背景图片自动旋转的方法
网络编程 2021-07-04 21:47www.168986.cn编程入门
这篇文章主要介绍了js根据鼠标移动速度背景图片自动旋转的方法,实例分析了javascript操作鼠标与图片的技巧,具有一定参考借鉴价值,需要的朋友可以参考下
本文实例讲述了js根据鼠标移动速度背景图片自动旋转的方法。分享给大家供大家参考。具体实现方法如下
代码如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://.w3./TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://.w3./1999/xhtml">
<head>
<title>js实现图片快速旋转围绕的鼠标</title>
<meta http-equiv="content-type" content="text/html;charset=gb2312">
</head>
<body>
<script language="JavaScript">
<!--
var images='/favicon.ico';
var amount=7;
var speed=1;
var RunTime = 0;
var tr=0;
var xtr=100;
var pulse=25;
var Xpos = 0;
var Ypos = 0;
var _y;
var temp;
/If you use an image larger or smaller than the one I've used
the cursor will be off center.Alter the 2 variables below to center it./
var UpDown=-10;
var LeftRight=-5;
if (document.all){
document.write('<div id="ieDiv" style="position:absolute;:0px;left:0px">');
document.write('<div id="c" style="position:relative">');
for (n=0; n < amount; n++)
document.write('<img src="'+images+'" style="position:absolute;:0px;left:0px;visibility:hidden">');
document.write('</div>');
document.write('</div>');
function FollowMouse(){
Xpos = document.body.scrollLeft+event.x+UpDown;
Ypos = document.body.scrollTop+event.y+LeftRight;
}
document.onmousemove = FollowMouse;
}
else if (document.layers){
window.captureEvents(Event.MOUSEMOVE);
function xFollowMouse(evnt){
Xpos = evnt.pageX+UpDown;
Ypos = evnt.pageY+LeftRight;
}
window.onMouseMove = xFollowMouse;
for (ns=0; ns < amount; ns++)
document.write("<LAYER NAME='n"+ns+"' LEFT='0' TOP='0' VISIBILITY='HIDE'><IMG SRC='"+images+"'></LAYER>");
}
function msi(){
if (document.layers){
for ( i = 0 ; i < ns ; i++ )
{
temp="n"+i
document.layers[0].visibility='show';
document.layers[0]. = Ypos+trMath.cos((RunTime+i4.5)/5);
document.layers[0].left =Xpos+trMath.sin((RunTime+i4.5)/5);
}
tr+=1;
RunTime+=speed;
stp=setTimeout('msi()',10);
if (tr>=100)
{
tr=100;
speed=2.5;
for ( i = 0 ; i < ns ; i++ )
{
temp="n"+i
document.layers[temp].visibility='show';
document.layers[temp].=Ypos+trMath.cos((RunTime-100)i/90);
document.layers[temp].left=Xpos+trMath.sin((RunTime-100)i/90);
}
}
if (RunTime>182)
{
speed=0.5;
for ( i = 0 ; i < ns ; i++ )
{
temp="n"+i
document.layers[temp].=Ypos+xtrMath.cos(((RunTime-182)+i4.5)/5);
document.layers[temp].left=Xpos+xtrMath.sin(((RunTime-182)+i4.5)/5)Math.cos((RunTime-182)/5);
}
}
}
else if (document.all){
for (i=0;i<ieDiv.all.c.all.length;i++)
{
ieDiv.all.c.all[0].style.visibility='visible';
ieDiv.all.c.all[0].style.=Ypos+trMath.cos((RunTime+i4.5)/5);
ieDiv.all.c.all[0].style.left=Xpos+trMath.sin((RunTime+i4.5)/5);
}
tr+=1;
RunTime+=speed;
stp=setTimeout('msi()',10);
if (tr>=100)
{
tr=100;
speed=2.5;
for (i=0;i<ieDiv.all.c.all.length;i++)
{
ieDiv.all.c.all[i].style.visibility='visible';
ieDiv.all.c.all[i].style.=Ypos+trMath.cos((RunTime-100)i/90);
ieDiv.all.c.all[i].style.left=Xpos+trMath.sin((RunTime-100)i/90);
}
}
if (RunTime>182)
{
speed=0.5;
for (i=0;i<ieDiv.all.c.all.length;i++)
{
ieDiv.all.c.all[i].style.=Ypos+xtrMath.cos(((RunTime-182)+i4.5)/5);
ieDiv.all.c.all[i].style.left=Xpos+xtrMath.sin(((RunTime-182)+i4.5)/5)Math.cos((RunTime-182)/5);
}
}
}
if (RunTime>210)
{
xtr-=10;
}
if (document.layers)
_y=-window.innerWidth-90;
else if (document.all)
_y=-document.body.clientWidth-90;
if (xtr <= _y)
{
RunTime=0;
speed=1;
tr=0;
xtr=100;
}
}
msi()
//-->
</script>
<script language="Javascript">
<!--
function selectAll(theField){
var tempval=eval("document."+theField)
tempval.focus()
tempval.select()
}
//-->
</script>
</body>
</html>
<html xmlns="http://.w3./1999/xhtml">
<head>
<title>js实现图片快速旋转围绕的鼠标</title>
<meta http-equiv="content-type" content="text/html;charset=gb2312">
</head>
<body>
<script language="JavaScript">
<!--
var images='/favicon.ico';
var amount=7;
var speed=1;
var RunTime = 0;
var tr=0;
var xtr=100;
var pulse=25;
var Xpos = 0;
var Ypos = 0;
var _y;
var temp;
/If you use an image larger or smaller than the one I've used
the cursor will be off center.Alter the 2 variables below to center it./
var UpDown=-10;
var LeftRight=-5;
if (document.all){
document.write('<div id="ieDiv" style="position:absolute;:0px;left:0px">');
document.write('<div id="c" style="position:relative">');
for (n=0; n < amount; n++)
document.write('<img src="'+images+'" style="position:absolute;:0px;left:0px;visibility:hidden">');
document.write('</div>');
document.write('</div>');
function FollowMouse(){
Xpos = document.body.scrollLeft+event.x+UpDown;
Ypos = document.body.scrollTop+event.y+LeftRight;
}
document.onmousemove = FollowMouse;
}
else if (document.layers){
window.captureEvents(Event.MOUSEMOVE);
function xFollowMouse(evnt){
Xpos = evnt.pageX+UpDown;
Ypos = evnt.pageY+LeftRight;
}
window.onMouseMove = xFollowMouse;
for (ns=0; ns < amount; ns++)
document.write("<LAYER NAME='n"+ns+"' LEFT='0' TOP='0' VISIBILITY='HIDE'><IMG SRC='"+images+"'></LAYER>");
}
function msi(){
if (document.layers){
for ( i = 0 ; i < ns ; i++ )
{
temp="n"+i
document.layers[0].visibility='show';
document.layers[0]. = Ypos+trMath.cos((RunTime+i4.5)/5);
document.layers[0].left =Xpos+trMath.sin((RunTime+i4.5)/5);
}
tr+=1;
RunTime+=speed;
stp=setTimeout('msi()',10);
if (tr>=100)
{
tr=100;
speed=2.5;
for ( i = 0 ; i < ns ; i++ )
{
temp="n"+i
document.layers[temp].visibility='show';
document.layers[temp].=Ypos+trMath.cos((RunTime-100)i/90);
document.layers[temp].left=Xpos+trMath.sin((RunTime-100)i/90);
}
}
if (RunTime>182)
{
speed=0.5;
for ( i = 0 ; i < ns ; i++ )
{
temp="n"+i
document.layers[temp].=Ypos+xtrMath.cos(((RunTime-182)+i4.5)/5);
document.layers[temp].left=Xpos+xtrMath.sin(((RunTime-182)+i4.5)/5)Math.cos((RunTime-182)/5);
}
}
}
else if (document.all){
for (i=0;i<ieDiv.all.c.all.length;i++)
{
ieDiv.all.c.all[0].style.visibility='visible';
ieDiv.all.c.all[0].style.=Ypos+trMath.cos((RunTime+i4.5)/5);
ieDiv.all.c.all[0].style.left=Xpos+trMath.sin((RunTime+i4.5)/5);
}
tr+=1;
RunTime+=speed;
stp=setTimeout('msi()',10);
if (tr>=100)
{
tr=100;
speed=2.5;
for (i=0;i<ieDiv.all.c.all.length;i++)
{
ieDiv.all.c.all[i].style.visibility='visible';
ieDiv.all.c.all[i].style.=Ypos+trMath.cos((RunTime-100)i/90);
ieDiv.all.c.all[i].style.left=Xpos+trMath.sin((RunTime-100)i/90);
}
}
if (RunTime>182)
{
speed=0.5;
for (i=0;i<ieDiv.all.c.all.length;i++)
{
ieDiv.all.c.all[i].style.=Ypos+xtrMath.cos(((RunTime-182)+i4.5)/5);
ieDiv.all.c.all[i].style.left=Xpos+xtrMath.sin(((RunTime-182)+i4.5)/5)Math.cos((RunTime-182)/5);
}
}
}
if (RunTime>210)
{
xtr-=10;
}
if (document.layers)
_y=-window.innerWidth-90;
else if (document.all)
_y=-document.body.clientWidth-90;
if (xtr <= _y)
{
RunTime=0;
speed=1;
tr=0;
xtr=100;
}
}
msi()
//-->
</script>
<script language="Javascript">
<!--
function selectAll(theField){
var tempval=eval("document."+theField)
tempval.focus()
tempval.select()
}
//-->
</script>
</body>
</html>
希望本文所述对大家的javascript程序设计有所帮助。
编程语言
- 如何快速学会编程 如何快速学会ug编程
- 免费学编程的app 推荐12个免费学编程的好网站
- 电脑怎么编程:电脑怎么编程网咯游戏菜单图标
- 如何写代码新手教学 如何写代码新手教学手机
- 基础编程入门教程视频 基础编程入门教程视频华
- 编程演示:编程演示浦丰投针过程
- 乐高编程加盟 乐高积木编程加盟
- 跟我学plc编程 plc编程自学入门视频教程
- ug编程成航林总 ug编程实战视频
- 孩子学编程的好处和坏处
- 初学者学编程该从哪里开始 新手学编程从哪里入
- 慢走丝编程 慢走丝编程难学吗
- 国内十强少儿编程机构 中国少儿编程机构十强有
- 成人计算机速成培训班 成人计算机速成培训班办
- 孩子学编程网上课程哪家好 儿童学编程比较好的
- 代码编程教学入门软件 代码编程教程