怎樣讓onmouseover和out觸發(fā)兩個函數(shù)?
是這樣的,我按老師教的寫了div的勻速運動函數(shù),又寫了div的透明度變化函數(shù)。我想把兩個效果一起DOM給onmouseover,結(jié)果發(fā)現(xiàn)只能觸發(fā)一個函數(shù),誰寫在前面觸發(fā)誰。這怎么辦啊,難道onmouse只能有一個動畫效果嗎?
-----------我是分割線-------------------------------------------------------------------
window.onload = function() {
?? ?var close = document.getElementById('menu');
?? ?function class1() {
?? ??? ?startMove(0),
?? ??? ?startOpactiy(100);
?? ?}
?? ?function class2() {
?? ??? ?startMove(-200),
?? ??? ?startOpactiy(30);
?? ?}
?? ?close.onmouseover = function() {
?? ??? ?class1()
?? ?};
?? ?close.onmouseout = function() {
?? ??? ?class2()
?? ?}
}
var timer = null;
var alpha = 30;
function startMove(ev) {
?? ?var close = document.getElementById('menu');
?? ?clearInterval(timer);
?? ?var speed = 0;
?? ?timer = setInterval(function() {
?? ??? ?if (close.offsetLeft < ev) {
?? ??? ??? ?speed = 10;
?? ??? ?} else {
?? ??? ??? ?speed = -10
?? ??? ?}
?? ??? ?if (close.offsetLeft == ev) {
?? ??? ??? ?clearInterval(timer)
?? ??? ?} else {
?? ??? ??? ?close.style.left = menu.offsetLeft + speed + 'px'
?? ??? ?}
?? ?}, 30)
}
function startOpactiy(target) {
?? ?var close = document.getElementById('menu');
?? ?clearInterval(timer);
?? ?var speed = 0;
?? ?timer = setInterval(function() {
?? ??? ?if (alpha > target) {
?? ??? ??? ?speed = -10;
?? ??? ?} else {
?? ??? ??? ?speed = 10;
?? ??? ?}
?? ??? ?if (alpha == target) {
?? ??? ??? ?clearInterval(timer)
?? ??? ?} else {
?? ??? ??? ?alpha += speed;
?? ??? ??? ?close.style.filter = 'alpha(opacity=' + alpha + ')';
?? ??? ??? ?close.style.opacity = alpha / 100;
?? ??? ?}
?? ?}, 30)
}
2016-03-18
不好意思已經(jīng)解決了,原來需要兩個定時器。。。。哈哈哈哈哈