一个小方块,从左上角,滑到右下角,弹回来左上,这个js如何写 一个小方块,从左上角,滑到右下角,弹回来左上,这个js如何写 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 没有明白楼主的具体含义,动态的移动?是指TWEEN函数的效果么? 这个用HTML中的marquee标签即可完成,具体用法网上有很多;如果只想用JS来实现,参见这个资源:http://download.csdn.net/source/1112445 <script>var o, t, b;b = true;function initFly(){ o = document.createElement("div"); o.style.position = "absolute"; o.style.width = 50; o.style.height = 50; o.style.left = 0; o.style.top = 0; o.style.background = "blue"; document.body.appendChild(o);}function startFly(){ t = setInterval("Fly()", 50)}function stopFly(){ clearInterval(t);}function Fly(){ var iLeft = parseInt(o.style.left); var iTop = parseInt(o.style.top); if(b) { if((iLeft <= document.body.clientWidth - 50) && (iTop <= document.body.clientHeight - 50)) { o.style.left = iLeft + 5; o.style.top = iTop + 3; } else b = false; } else if((iLeft >= 0) && (iTop >= 0)) { o.style.left = iLeft - 5; o.style.top = iTop - 3; } else b = true}</script><body onload="initFly()"><br /><br /><br /><input type="button" value="start" onclick="startFly()"><input type="button" value="stop" onclick="stopFly()"> 发现csdn上各种马甲啊资源分闹的吧...我也是很多个马甲... jquery问题,请高手指点,是否应用回调还是哪里有错啊 javascript air大侠帮忙解释下 EXT GWT问题 大家帮我看看这段代码,拒绝访问问题 ie浏览器下js中如何改变object标签下的date属性 JS 对象能存控件么? 有关带参数的链接问题!在线等待 有关下拉框的问题2 void(0)什么意思!vSrc = window.event.srcElement;什么意思一定要说说event对象的意义和内容 在后台上怎么实现跨页面的数据交互? 如何用Jquery 编写一个俄罗斯方块 程序 在js中改css的样式
如果只想用JS来实现,参见这个资源:http://download.csdn.net/source/1112445
var o, t, b;
b = true;function initFly()
{
o = document.createElement("div");
o.style.position = "absolute";
o.style.width = 50;
o.style.height = 50;
o.style.left = 0;
o.style.top = 0;
o.style.background = "blue";
document.body.appendChild(o);
}function startFly()
{
t = setInterval("Fly()", 50)
}function stopFly()
{
clearInterval(t);
}function Fly()
{
var iLeft = parseInt(o.style.left);
var iTop = parseInt(o.style.top);
if(b)
{
if((iLeft <= document.body.clientWidth - 50) && (iTop <= document.body.clientHeight - 50))
{
o.style.left = iLeft + 5;
o.style.top = iTop + 3;
}
else
b = false;
}
else
if((iLeft >= 0) && (iTop >= 0))
{
o.style.left = iLeft - 5;
o.style.top = iTop - 3;
}
else
b = true
}
</script><body onload="initFly()">
<br /><br /><br />
<input type="button" value="start" onclick="startFly()"><input type="button" value="stop" onclick="stopFly()">
资源分闹的吧...
我也是很多个马甲...