精准定位元素+解決瀏覽器窗口大小改變時,頁面錯位的問題


 

首先,定位元素時,范圍越小越精准,對其他頁面的影響越小,

所以,這個事件我沒有用整個window,而是定位到了that.FormProp.mainTable這個元素,在設置樣式時,也只設置了這個范圍內的元素,

比如:$(">div.vAction>.vActionSelect", that.FormProp.mainTable),這樣寫查找的更快,更精確。

言歸正傳,加上以下代碼,就能避免當窗口縮放時,頁面出現錯亂的現象。這樣,盒子會隨着窗口寬度的改變而調整自己的寬度。

$(that.FormProp.mainTable).scroll(function () {
let tops = parseInt($(">div.vAction>div.vActionSelect", that.FormProp.mainTable).css('top'));//To position the top value of the box
tops = $(that.FormProp.mainTable).scrollTop() - 100;//Here, the top value of the box will change with the position of the scroll bar
$(">div.vAction>.vActionSelect", that.FormProp.mainTable).css('top', top + 'px')//Finally, assign the top value to the box
});


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM