function moveElement(elementID,final_x,final_y,interval) {
if (!document.getElementById) return false;
if (!document.getElementById(elementID)) return false;
var elem = document.getElementById(elementID);
if (elem.movement) {
clearTimeout(elem.movement);
}
if (!elem.style.left) {
elem.style.left = "0px";
}
if (!elem.style.top) {
elem.style.top = "0px";
}
var xpos = parseInt(elem.style.left);
var ypos = parseInt(elem.style.top);
if (xpos == final_x && ypos == final_y) {
return true;
}
if (xpos < final_x) {
var dist = Math.ceil((final_x - xpos)/10);
xpos = xpos + dist;
}
if (xpos > final_x) {
var dist = Math.ceil((xpos - final_x)/10);
xpos = xpos - dist;
}
if (ypos < final_y) {
var dist = Math.ceil((final_y - ypos)/10);
ypos = ypos + dist;
}
if (ypos > final_y) {
var dist = Math.ceil((ypos - final_y)/10);
ypos = ypos - dist;
}
elem.style.left = xpos + "px";
elem.style.top = ypos + "px";
var repeat = "moveElement('"+elementID+"',"+final_x+","+final_y+","+interval+")";
elem.movement = setTimeout(repeat,interval);
}
if (!document.getElementById) return false;
if (!document.getElementById(elementID)) return false;
var elem = document.getElementById(elementID);
if (elem.movement) {
clearTimeout(elem.movement);
}
if (!elem.style.left) {
elem.style.left = "0px";
}
if (!elem.style.top) {
elem.style.top = "0px";
}
var xpos = parseInt(elem.style.left);
var ypos = parseInt(elem.style.top);
if (xpos == final_x && ypos == final_y) {
return true;
}
if (xpos < final_x) {
var dist = Math.ceil((final_x - xpos)/10);
xpos = xpos + dist;
}
if (xpos > final_x) {
var dist = Math.ceil((xpos - final_x)/10);
xpos = xpos - dist;
}
if (ypos < final_y) {
var dist = Math.ceil((final_y - ypos)/10);
ypos = ypos + dist;
}
if (ypos > final_y) {
var dist = Math.ceil((ypos - final_y)/10);
ypos = ypos - dist;
}
elem.style.left = xpos + "px";
elem.style.top = ypos + "px";
var repeat = "moveElement('"+elementID+"',"+final_x+","+final_y+","+interval+")";
elem.movement = setTimeout(repeat,interval);
}
解决方案 »
- JQuery EasyUI combotree如何得到Multiple Select多选框内的值
- JQ的焦点幻灯图片,为什么在IE6下显示会错位?
- 问个onclick的问题
- 如何控制iframe潜入页面内部文字的字体????结帖再加30分
- 一个函数.我没见过这种.
- 又是模态窗口的问题,请高手进来帮我看看!!!!!!!!!!!
- javascript中如何读取当前网站地址
- 如何得到一个按纽或者<input type="text"> 再屏幕上的坐标位置?
- csdn的论坛列表这个菜单是怎么做的
- 微信java开发 微信页面穿透事件怎么解决?
- input的type=image的问题
- winow.showModalDialog()弹出窗体右上角的关闭按钮不可用 javascript 弹出窗体 关闭按钮不可用
<style>
div#div1 {display:inline; width:100px; height:100px; background:#f22; position:absolute;}
</style>
<input type="button" id="bt_act" value="移" onclick="moveIt(200,300);"/>
<div id="div1">
</div>
<script type="text/javascript">
function moveIt(x,y){
$("#div1").animate({ left:x, top:y});
}
</script>
不过要引用一个54kb的js文件
咋看都不值!:)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html>
<head>
<title></title>
<style type="text/css">
.css{
width:100px;
height:100px;
filter:alpha(opacity=50);
POSITION: absolute;
left:100px;
top:100px;
background: url("http://images.movie.xunlei.com/gallery/432/552e18a73d33cc7cd45b1c3305342481.jpg");
border-width: 2px;
border-color: #0000ff;
border-style: outset;
}
</style>
<script language="javascript">
var i=100;
function move(){
if(i>400){
clearInterval(intervalID);
}
i++;
document.getElementById("m_id").style.left=i+"px";
}
</script>
</head>
<body>
<pre>
.css{
width:100px;
height:100px;
filter:alpha(opacity=50);
POSITION: absolute;
left:100px;
top:100px;
background: url("http://images.movie.xunlei.com/gallery/432/552e18a73d33cc7cd45b1c3305342481.jpg");
border-width: 2px;
border-color: #0000ff;
border-style: outset;
}
var i=0;
function move(){
i++;
document.getElementById("m_id").style.left=i+"px";
}
}</pre>
<div id="m_id" class="css"></div>
<script language="javascript">
var intervalID = setInterval(move,10);
</script>
</body>
</html>
做好静态文件的 cache
在一定程度上,是值的.
<head>
<title></title>
<style type="text/css">
.css{
width:100px;
height:100px;
filter:alpha(opacity=50);
POSITION: absolute;
left:100px;
top:100px;
background: url("http://images.movie.xunlei.com/gallery/432/552e18a73d33cc7cd45b1c3305342481.jpg");
border-width: 2px;
border-color: #0000ff;
border-style: outset;
}
</style>
<script language="javascript">
var i=100;
function move(){
if(i>400){
clearInterval(intervalID);
}
i++;
document.getElementById("m_id").style.left=i+"px";
}
</script>
</head>
<body>
<pre>
.css{
width:100px;
height:100px;
filter:alpha(opacity=50);
POSITION: absolute;
left:100px;
top:100px;
background: url("http://images.movie.xunlei.com/gallery/432/552e18a73d33cc7cd45b1c3305342481.jpg");
border-width: 2px;
border-color: #0000ff;
border-style: outset;
}
var i=0;
function move(){
i++;
document.getElementById("m_id").style.left=i+"px";
}
}</pre>
<div id="m_id" class="css"></div>
<script language="javascript">
var intervalID = setInterval(move,10);
</script>
</body>
</html>