oa1.onmousemove = function (ev) { var oEvnt = ev || event; var x = oEvnt.clientX - oa1.offsetLeft; var y = oEvnt.clientY - oa1.offsetTop; console.log(x, y); oa2.style.left = -(x * 2 - 100) + 'px';//問題用clientWidth為什么是NAN oa2.style.top = -(y * 2 - 100) + 'px'; if (x >= oa1.clientWidth - (oDiv.clientWidth / 2)) { oDiv.style.top = oa1.clientHeight - oDiv.clientHeight + "px"; } else { oDiv.style.top = y - 50 + "px"; } if (oEvnt.clientY - oa1.offsetTop >= oa1.clientHeight - oDiv.clientHeight / 2) { oDiv.style.left = oa1.clientWidth - oDiv.clientWidth + "px" } else { oDiv.style.left = x - 50 + "px"; } };在上面的if條件我想的是當鼠標劃到離a標簽邊距只有50px就讓div的top值固定為一個值。上面只是部分代碼。也許我用判斷語句不是很合適,請教這位大神如何解決?
if里面的判斷不理想,請大神出個解決方案?
泛舟湖上清波郎朗
2018-09-17 07:07:38