亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

為啥我的鼠標移出來的效果不顯示。。。。。

window.onload = function(){

var box = document.getElementById('box') ;?

box.onmouseover = function(){

play(1);

}

box.onmouseout = function(){

play(0.3);

}

}

var alpha = 0.3 ;

function play(target){

var timer = null ;

var box = document.getElementById('box') ;?

clearInterval(timer);

timer = setInterval(function(){

var speed = 0 ;

if(alert > target){

speed = -0.1;

}else{

speed = 0.1 ;

}

if(alpha == target){

clearInterval(timer);

}else{

alpha = alpha + speed;

box.style.opacity = alpha;

}

},30);

}

就是看不出是哪里錯了。。。。

正在回答

4 回答

window.onload = function() {

var box = document.getElementById('box');

box.onmouseover = function() {

play(1);

}

box.onmouseout = function() {

play(0.3);

}

}

var alpha = 0.3;

var timer = null;


function play(target) {

clearInterval(timer);

var box = document.getElementById('box');

var speed = 0;

timer = setInterval(function() {

if(alpha > target) {

speed = -0.01;?

} else {

speed = 0.01;

}

if(alpha == target) {

clearInterval(timer);

} else {

alpha = alpha + speed;

box.style.opacity = alpha;

}

}, 3);

}

這個是我復制你的代碼之后拉過去改的 ?測試可以 你對照下


1 回復 有任何疑惑可以回復我~
#1

任性不是罪 提問者

好噠,非常感謝?。?!thank you !!!
2016-07-25 回復 有任何疑惑可以回復我~

window.onload = function() {

var box = document.getElementById('box');

box.onmouseover = function() {

play(100);

}

box.onmouseout = function() {

play(30);

}

var timer = null;//這倆貨既不在上面的{}里

var alpha = 30;//也不在下面的{}里

function play(target) {

clearInterval(timer);

timer = setInterval(function() {

var speed = 0;

if(alpha > target) {

speed = -10;

} else {

speed = 10;

}

if(alpha == target) {

clearInterval(timer);

} else {

alpha += speed;

box.style.opacity = alpha / 100;

}

}, 30);

}


}


0 回復 有任何疑惑可以回復我~
#1

腦闊疼

這個涉及到作用域的問題 全局變量 和臨時變量 建議你看看
2016-07-25 回復 有任何疑惑可以回復我~
#2

任性不是罪 提問者 回復 腦闊疼

恩呢,好噠
2016-07-25 回復 有任何疑惑可以回復我~

window.onload = function(){

var box = document.getElementById('box') ;?

var timer = null ;

box.onmouseover = function(){

play(100);

}

box.onmouseout = function(){

play(30);

}

function play(target){

var alpha = 30 ;

clearInterval(timer);

timer = setInterval(function(){

var speed = 0 ;

if(alpha > target){

speed = -10;

}else{

speed = 10 ;

}

if(alpha == target){

clearInterval(timer);

}else{

alpha += speed;

box.style.opacity = alpha/100;

}

},30);

}


}


0 回復 有任何疑惑可以回復我~

第一:

if(alert > target){//這里應該是 alpha

speed = -0.1;

}else{

speed = 0.1 ;

}

第二:

function play(target){

var timer = null ;//這個變量應該聲明在方法體外面。

var box = document.getElementById('box') ;?


clearInterval(timer);


第三:

speed的絕對值為0.1 最后鼠標移出div可能會閃屏 ?建議縮小 然后同時縮小相應倍數計時器的間隔時間 達到效果不變


0 回復 有任何疑惑可以回復我~
#1

任性不是罪 提問者

已經全部改過來了,可是還是不行。。。。
2016-07-25 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

為啥我的鼠標移出來的效果不顯示。。。。。

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號