跟隨視頻寫(xiě)到11分鐘左右?測(cè)試失敗
報(bào)錯(cuò)信息:
Uncaught?TypeError:?Cannot?read?property?'offsetTop'?of?null
????at?HTMLDivElement.fnDown?(drag.js:26)
????
源碼:
function?getByClass(clsName,?parent)?{
????var?oParent?=?parent???document.getElementById(parent)?:?document,
????????eles?=?[],
????????elements?=?oParent.getElementsByTagName('*');
????for?(var?i?=?0,?l?=?elements.length;?i?<?l;?i++)?{
????????if?(elements[i].className?==?clsName)?{
????????????eles.push(elements[i]);
????????}
????}
????return?eles;
}
window.onload?=?drag;
function?drag()?{
????var?oTitle?=?getByClass('login_logo_webqq',?'loginPanel')[0];
????oTitle.onmousedown?=?fnDown;
}
function?fnDown(event)?{
????event?=?event?||?window.event;
????var?oDrag?=?document.getElementById('loginPane1'),
????????//??光標(biāo)按下時(shí)光標(biāo)和面板之間的距離?相對(duì)XY
????????disX?=?event.clientX?-?oDrag.offsetLeft,
????????disY?=?event.clientY?-?oDrag.offsetTop;
????//??移動(dòng)
????document.onmousemove?=?function?(event)?{
????????event?=?event?||?window.event;
????????fnMove(event,?disX,?disY);
????}
}
function?fnMove(e,?posX,?posY)?{
????var?oDrag?=?document.getElementById('loginPane1'),
????????l?=?e.clientX?-?posX,
????????t?=?e.clientY?-?posY;
????oDrag.style.left?=?l?+?'px';
????oDrag.style.top?=?t?+?'px';
}
2018-04-11
?
disX?=?event.clientX?-?oDrag.offsetLeft, ?這一句應(yīng)該以分號(hào)結(jié)尾,不是逗號(hào)。