為啥我的鼠標(biāo)移出來的效果不顯示。。。。。
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);
}
就是看不出是哪里錯(cuò)了。。。。
2016-07-25
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);
}
這個(gè)是我復(fù)制你的代碼之后拉過去改的 ?測(cè)試可以 你對(duì)照下
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);
}
}
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);
}
}
2016-07-25
第一:
if(alert > target){//這里應(yīng)該是 alpha
speed = -0.1;
}else{
speed = 0.1 ;
}
第二:
function play(target){
var timer = null ;//這個(gè)變量應(yīng)該聲明在方法體外面。
var box = document.getElementById('box') ;?
clearInterval(timer);
第三:
speed的絕對(duì)值為0.1 最后鼠標(biāo)移出div可能會(huì)閃屏 ?建議縮小 然后同時(shí)縮小相應(yīng)倍數(shù)計(jì)時(shí)器的間隔時(shí)間 達(dá)到效果不變