1 回答

TA貢獻1770條經驗 獲得超3個贊
在您的情況下,有兩種方法可以根據視口調整頁面。一種方法是使用@media-queries并顯示/隱藏具有該屬性的一個或另一個元素display。
這將允許您根據屏幕尺寸調整代碼。
@media only screen and (min-width: 1024px) and (max-width: 1024px) {
// in your case: hide an element, show the other
#desktopMenu { display:none;} // or display block etc
}
您可以設置width或height按照您的意愿設置。
這是有關媒體查詢的更多信息
您還可以獲取當前視口值,如下所示:
// Size of browser viewport.
var width = window.innerWidth;
var height = window.innerHeight;
然后根據情況調整您的代碼:
if (height >= yourValue) { // or however you want to check the height
document.getElementById('button').setAttribute('data-target', '#desktopMenu'); // or however you want to add/change attributes
}
希望有幫助
- 1 回答
- 0 關注
- 140 瀏覽
添加回答
舉報