大家好,我想要在網(wǎng)頁(yè)上作視差滾動(dòng)的效果,於是寫(xiě)了一段javascript插在html裡:<img class="graphic_001" src="img/parallax_graphic/tri-yellow.svg"/> <script type="text/javascript">
function parallex () { var img = window.pageYOffset; var a = document.getElementsByClassName('graphic_001'); var speed = 0.8;
a.style.top = img * speed +'px';
} window.addEventListener('scroll',parallex); </script>但是打開(kāi)瀏覽器之後,瀏覽器報(bào)錯(cuò)沒(méi)有抓到圖片的top,而且只要一滾動(dòng)就會(huì)報(bào)錯(cuò):想請(qǐng)問(wèn)應(yīng)該怎麼修正javascript呢?目前確認(rèn)圖片是有載到網(wǎng)頁(yè)上的,謝謝大家的回答!
javascript抓不到圖片的top?
慕哥6287543
2018-08-03 16:25:37