為什么我的不能進(jìn)行鏈?zhǔn)竭\(yùn)動(dòng)
window.onload = function() {
?? ??? ??? ??? ?var Li = document.getElementById('li1');
?? ??? ??? ??? ?Li.onmouseover = function() {
?? ??? ??? ??? ??? ?startMove(Li, 'width', 400, function() {
?? ??? ??? ??? ??? ??? ?startMove(Li, 'height', 200, function() {
?? ??? ??? ??? ??? ??? ??? ?startMove(Li, 'opacity', 100);
?? ??? ??? ??? ??? ??? ?});
?? ??? ??? ??? ??? ?});
?? ??? ??? ??? ?}
?? ??? ??? ??? ?Li.onmouseout = function() {
?? ??? ??? ??? ??? ?startMove(Li, 'opacity', 30, function() {
?? ??? ??? ??? ??? ??? ?startMove(Li, 'height', 100, function() {
?? ??? ??? ??? ??? ??? ??? ?startMove(Li, 'width', 200);
?? ??? ??? ??? ??? ??? ?});
?? ??? ??? ??? ??? ?});
?? ??? ??? ??? ?}
?? ??? ??? ?}
move.js
function startMove(obj, attr, target, fn) {
?? ?clearInterval(obj.timer);
?? ?obj.timer = setInterval(function() {
?? ??? ?//獲取當(dāng)前的值
?? ??? ?var icur = 0;
?? ??? ?if(attr == 'opacity') {
?? ??? ??? ?icur = Math.round(parseFloat(getStyle(obj, attr)) * 100);
?? ??? ?} else {
?? ??? ??? ?icur = parseInt(getStyle(obj, attr));
?? ??? ?}
?? ??? ?//2算速度
?? ??? ?var speed = (target - icur) / 8;
?? ??? ?speed = speed > 0 ? Math.ceil(speed) : Math.floor(speed);
?? ??? ?//3檢測(cè)停止
?? ??? ?if(icur == target) {
?? ??? ??? ?clearInterval(obj.timer);
?? ??? ??? ?if(fn) {
?? ??? ??? ??? ?fn();
?? ??? ??? ?}
?? ??? ?} else {
?? ??? ??? ?if(attr == 'opacity') {
?? ??? ??? ??? ?obj.style.filter = 'alpha(opacity:' + icur + speed+ ')'; //IE
?? ??? ??? ??? ?obj.style.opacity = (icur + speed) / 100;
?? ??? ??? ?} else {
?? ??? ??? ??? ?obj.style[attr] = icur + speed + 'px';
?? ??? ??? ?}
?? ??? ?}
?? ?}, 30);
}
function getStyle(obj, attr) {
?? ?if(obj.currentStyle) {
?? ??? ?return obj.currentStyle[attr];
?? ?} else {
?? ??? ?return getComputedStyle(obj, false)[attr];
?? ?}
}
2016-09-27
2016-09-20
有可能是瀏覽器的問(wèn)題,你把代碼復(fù)制到慕課網(wǎng)寫(xiě)代碼的地方,測(cè)試一下,如果可以,那就是瀏覽器的問(wèn)題了。
因?yàn)槲业拇a也有問(wèn)題,測(cè)試傳入fn函數(shù)參數(shù)時(shí),總是顯示錯(cuò)誤:參數(shù)后面少")"。拿到慕課網(wǎng)測(cè)試,又可以傳入函數(shù)參數(shù)。至于具體神馬問(wèn)題,憋問(wèn)我,目前我也不知道,望有學(xué)霸解答一下。
2016-09-13
我把你的代碼拷下來(lái)運(yùn)行可以鏈?zhǔn)竭\(yùn)動(dòng)啊,你是不是HTML順序沒(méi)寫(xiě)對(duì)?要這樣寫(xiě)
先引move.js再window.onload