筆記,遺留的兩個疑問
標簽:
JavaScript
var timer = null;
var timer2 = null;
var flag = 0;
window.onload = function(){
var slip = document.getElementById('wrap');
var Blocks = document.getElementById('listpanel').getElementsByTagName('div');
slip.onmouseover = function(){
move(0);
}
slip.onmouseout = function(){
move(-280);
}
for(var i = 0;i < Blocks.length;i++)
{
var id = Blocks[i];
id.onmouseover = function(){
change(id, 0.3, 1);
}
id.onmouseout = function(){
change(id, 1, 0.3);
}
}
}
function change(id, num, alpha){
clearInterval(timer2);
timer2 = setInterval(function(){
if(num == 0.3){
if(id.style.opacity > 0.3) alpha -= 0.1;
}else{
if(id.style.opacity < 1) alpha += 0.1;
}
if(id.style.opacity == num){
clearInterval(timer2);
}
else id.style.opacity = alpha; },100);
}
function move(Target){
var slip = document.getElementById('wrap');
clearInterval(timer);
timer = setInterval(function(){
var speed = 0;
if(slip.offsetLeft > Target) speed = -10;
if(slip.offsetLeft < Target) speed = 10;
if(slip.offsetLeft == Target){
clearInterval(timer);
}else slip.style.left = slip.offsetLeft + speed + 'px';},60);
}
疑问:①绑定事件onmouseout = function(){
change();
}直接使用change()会自动运行
②遍历绑定事件只有最后一个有效
點擊查看更多內(nèi)容
為 TA 點贊
評論
評論
共同學(xué)習,寫下你的評論
評論加載中...
作者其他優(yōu)質(zhì)文章
正在加載中
感謝您的支持,我會繼續(xù)努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進行掃碼打賞哦