在写js动画的时候不知道我为什么离开你为什么下面的代码,在鼠标离开的时候老是会不去

求大神帮我看下这代码,鼠标离开的时候,div不会回去呀?是什么问题?
&!DOCTYPE html&&html &&head& &meta http-equiv="Content-Type" content="text/ charset=UTF-8"/& &title&Js动画&/title&&style type="text/css"&&style&*{margin:0;padding:0;}#div1{width:200height:200background:position:left:-200top:0;}#div1 span{height: 50position:background:width: 20left: 200top: 75}&/style&&/head&&script type="text/javascript"& window.onload=function(){
var oDiv=document.getElementById('div1');
oDiv.onmouseover=function(){
startMove(0);
oDiv.onmouseout=function(){
startMove(-200);
} }var timer=function startMove(iTarget){ clearInterval(timer); var oDiv=document.getElementById('div1'); timer=setInterval(function(){
var speed= 0; if (oDiv.offsetLeft&iTarget) {
speed==-10; }else{
speed==10; } if(oDiv.offsetLeft==iTarget){
clearInterval(timer);
} else{ oDiv.style.left=oDiv.offsetLeft+speed+'px';
},30)}&/script&&body&&div id="div1"&&span id="share"&分享&/span&&/div&&/html&
非常感谢!已经解决了。
改过来之后,为什么鼠标移入移出时,动画效果的速度不一样??移出时动画退回去的速度明显比较慢。请问怎么改才能让它们移入移出时的速度一样快?
我的也是这样,你找出原因了吗?
写下你的评论...
哪里的88行和92行??总共才60几行...
写下你的评论...
Copyright (C)
All Rights Reserved | 京ICP备 号-2我写的鼠标移出的代码为什么当移出的时候为什么div一直颤抖,而不移出呢。
&!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/ charset=utf-8" /&&title&速度动画&/title&&style&body,div,span{ margin:0;
padding:0; } #div{ width:200 height:200 background: position: left:-200 top:0; } #share{ width:20 height:50 background: position: left:200 top:75 } &/style&&script&window.onload=function(){ var oDiv=document.getElementById('div'); oDiv.onmouseover=function(){
startMove();
} oDiv.onmouseout=function(){
startMove1();
} }var timer=function startMove(){ clearInterval(timer); var oDiv=document.getElementById('div'); setInterval(function(){
if(oDiv.offsetLeft==0){
clearInterval(timer);
}else{ oDiv.style.left=oDiv.offsetLeft+10+'px';
},30); }function startMove1(){ clearInterval(timer); var oDiv=document.getElementById('div'); setInterval(function(){
if(oDiv.offsetLeft==-200){
clearInterval(timer);
}else{ oDiv.style.left=oDiv.offsetLeft-10+'px';
&/script&&/head&&body&&div id="div"&&span id="share"&分享&/span&&/div&&/body&&/html&
加了这个代码压根就不执行了
我仔细检查了下,startMove和startMove这两个函数中,设定定时器的地方有问题。
第42行和第53行,应该是timer = setInterval(function(){
抱歉之前看错了。一定要加timer=
写下你的评论...
写下你的评论...
Copyright (C)
All Rights Reserved | 京ICP备 号-2想使用一个js写一个当鼠标放在菜单上的时候就会出现滚动条,当鼠标离开菜单栏的时候滚动条消失。_百度知道
想使用一个js写一个当鼠标放在菜单上的时候就会出现滚动条,当鼠标离开菜单栏的时候滚动条消失。
最好写详细点,给滚动条加些好看的样式。
我有更好的答案
此时子菜单使用【display=“block”】属性显示鼠标移动上去用【onmouseover】;鼠标离开用【onmouseout】,此时子菜单使用【display=“none”】隐藏
你这是在糊弄我啊
其他类似问题
为您推荐:
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁

我要回帖

更多关于 input鼠标离开事件 的文章

 

随机推荐