求JS滑动效果! 有一个div我希望鼠标经过它的时候,慢慢的移动位置,从右到左 移动 100px但是不是突然变换位置的,而是一步一步 慢慢滑动过来的。有这样的JS吗? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 这个很正常的代码到处都是。onmouseover时触发事件然后利用setTimeout改变div的位置。 那个速度你自己控制呗 setTimeout后面的 那个参数是毫秒。 <div id="d" style="width:100px;height:30px;background:#111;position:absolute;left:0px;" onmouseover="over();"></div><script type="text/javascript"> var ol,tm,obj,firstl; function move(){ if(!obj) obj = document.getElementById("d"); if(parseInt(obj.style.left) - firstl >=100){ clearInterval(tm);return ;} ol = parseInt(obj.style.left); obj.style.left = ++ol + "px"; } function over(){ firstl = parseInt(document.getElementById("d").style.left); tm = setInterval(move, 10); }</script> 这个我刚好有个例子,给lz看看<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><title>jquery-animate</title><script type="text/javascript" src="jquery-1.3.2.min.js" ></script><script>$(function(){ $("#panel1").mouseover(function(){ //if(!$(this).is(":animated")){ $(this).animate({left:"800px",height:"0px"},1000).animate({left:"0px",height:"100px"},4000); //} //if(!$("#panel2").is(":animated")){ $("#panel2").animate({left:"800px",height:"200px"},2000).animate({left:"0px",height:"100px"},3000); $("#panel3").animate({left:"800px",height:"0px"},3000).animate({left:"0px",height:"100px"},2000); $("#panel4").animate({left:"800px",height:"200px"},4000).animate({left:"0px",height:"100px"},1000); $("#panel5").animate({left:"800px",height:"0px"},3000).animate({left:"0px",height:"100px"},2000); $("#panel6").animate({left:"800px",height:"200px"},2000).animate({left:"0px",height:"100px"},3000); $("#panel7").animate({left:"800px",height:"0px"},1000).animate({left:"0px",height:"100px"},4000); //} }); }) </script><style>body{ overflow: hidden}.panel{ position:relative; width:200px; height:100px; border:1px solid #0050D0; background:#96e555; cursor:pointer; }</style></head><body><div id="panel1" class="panel"></div><div id="panel2" class="panel"></div><div id="panel3" class="panel"></div><div id="panel4" class="panel"></div><div id="panel5" class="panel"></div><div id="panel6" class="panel"></div><div id="panel7" class="panel"></div></body></html> .animate 这个动画,平滑度还是不错的 直接用jQuery吧,,一个函数就搞定了,还能调整各种效果 求各位大虾们帮帮忙啊,怎么让这个切换效果实现自动切换。 CSS问题 关于tabpanel中某个panel销毁的问题 如何设置当浏览器关闭的时候清空掉cookie 懂My97时间控件的朋友进,正解立刻给分 请教:javascript的下拉框在form中无法正常运行的问题 关于窗口关闭的新问题,以及隐去IE的菜单栏、地址栏、状态栏的问题 求助 一个VBScript的问题 如何在html 页面 include 其它页面 用JavaScript捕获ActiveX的事件,如果事件有参数怎么办? 60分,js滚条拖动后,单击左右按钮出现错误。 请问这两端正则有什么区别
onmouseover时触发事件
然后利用setTimeout改变div的位置。
<script type="text/javascript">
var ol,tm,obj,firstl;
function move(){
if(!obj) obj = document.getElementById("d");
if(parseInt(obj.style.left) - firstl >=100){ clearInterval(tm);return ;}
ol = parseInt(obj.style.left);
obj.style.left = ++ol + "px";
}
function over(){
firstl = parseInt(document.getElementById("d").style.left);
tm = setInterval(move, 10);
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>jquery-animate</title>
<script type="text/javascript" src="jquery-1.3.2.min.js" ></script>
<script>
$(function(){
$("#panel1").mouseover(function(){
//if(!$(this).is(":animated")){
$(this).animate({left:"800px",height:"0px"},1000).animate({left:"0px",height:"100px"},4000);
//}
//if(!$("#panel2").is(":animated")){
$("#panel2").animate({left:"800px",height:"200px"},2000).animate({left:"0px",height:"100px"},3000);
$("#panel3").animate({left:"800px",height:"0px"},3000).animate({left:"0px",height:"100px"},2000);
$("#panel4").animate({left:"800px",height:"200px"},4000).animate({left:"0px",height:"100px"},1000);
$("#panel5").animate({left:"800px",height:"0px"},3000).animate({left:"0px",height:"100px"},2000);
$("#panel6").animate({left:"800px",height:"200px"},2000).animate({left:"0px",height:"100px"},3000);
$("#panel7").animate({left:"800px",height:"0px"},1000).animate({left:"0px",height:"100px"},4000);
//}
});
})
</script>
<style>
body{ overflow: hidden}
.panel{
position:relative;
width:200px;
height:100px;
border:1px solid #0050D0;
background:#96e555;
cursor:pointer;
}
</style></head><body>
<div id="panel1" class="panel"></div>
<div id="panel2" class="panel"></div>
<div id="panel3" class="panel"></div>
<div id="panel4" class="panel"></div>
<div id="panel5" class="panel"></div>
<div id="panel6" class="panel"></div>
<div id="panel7" class="panel"></div></body>
</html>