1 回答

TA貢獻1770條經(jīng)驗 獲得超3個贊
在您的情況下,有兩種方法可以根據(jù)視口調(diào)整頁面。一種方法是使用@media-queries并顯示/隱藏具有該屬性的一個或另一個元素display。
這將允許您根據(jù)屏幕尺寸調(diào)整代碼。
@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
}
您可以設(shè)置width或height按照您的意愿設(shè)置。
這是有關(guān)媒體查詢的更多信息
您還可以獲取當前視口值,如下所示:
// Size of browser viewport.
var width = window.innerWidth;
var height = window.innerHeight;
然后根據(jù)情況調(diào)整您的代碼:
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 關(guān)注
- 135 瀏覽
添加回答
舉報