怎么加个开关。。控制重复执行,弄了好几天要崩溃了。
就是运动后 p2 跟span复位,再次点击后又重新运动了
window.onload = function(){
var op = document.getElementById('p1');
var op2 = document.getElementById('p2');
var aSpan = op.getElementsByTagName('span');
var len = 10;
var num =0;
var time = null;
for(var i=0;i<len;i++){
op.innerHTML += '<span style="left:'+i*40+'px">+1</span>'
}
op.onclick=function(){ //点击p1,p2回变宽透明,span 会向上透明,我想让他运动完后立马返回初始位置,再次点击又重新动了。
clearInterval(time)
time =setInterval(function(){
startMove(op2,{width:400,opacity:100},function(){
startMove(op2,{opacity:0})
})
startMove(aSpan[num],{bottom:100,opacity:0})
num++
if(num==len){
clearInterval(time)
}
},100)
}
function startMove(obj, json, fnEnd){
clearInterval(obj.timer);
obj.timer=setInterval(function (){
var bStop=true; //假设:所有值都已经到了
for(var attr in json){
var cur=0;
if(attr=='opacity'){
cur=Math.round(parseFloat(getStyle(obj, attr))*100);
}else{
cur=parseInt(getStyle(obj, attr));
}
var speed=(json[attr]-cur)/6;
speed=speed>0?Math.ceil(speed):Math.floor(speed);
if(cur!=json[attr])
bStop=false;
if(attr=='opacity'){
obj.style.filter='alpha(opacity:'+(cur+speed)+')';
obj.style.opacity=(cur+speed)/100;
}else{
obj.style[attr]=cur+speed+'px';
}
}
if(bStop){
clearInterval(obj.timer);
if(fnEnd)fnEnd();
}
}, 30);
}
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
重复执行?
楼主的意思是点击过后不断重复某个“效果”是不?
那就可以给这个p绑定一个事件,而这个事件的处理程序就是完成那个要不断重复的效果………