//獲取盒子 var divCen = document.getElementById("cenDiv"); //獲取圖片 var imgEde = document.getElementById("eduImg");//獲取...............................function showDiv(){ //可視區(qū)域 var clients = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight; var divTop = imgEde.getBoundingClientRect().top; if(divTop <= clients){ imgEde.classList.add("edu-cenImg"); } } window.onscroll = showDiv;我有很多個(gè)元素要使用這個(gè)方法,但每次都 獲取他的ID是不是太麻煩的點(diǎn)
這段函數(shù)怎么重復(fù)使用?
學(xué)長(zhǎng)大人
2017-03-24 15:11:41