3 回答

TA貢獻1827條經驗 獲得超8個贊
我沒有添加另一個 JavaScript 函數,而是在移動 CSS 媒體查詢中使用了下面的代碼。
@media screen and (max-width: 600px) {
/* Removing the Menu Underline For Ipad and Mobile */
.target {
display: none;
}
}

TA貢獻1780條經驗 獲得超4個贊
你可以嘗試用這個。希望它能起作用。
//User agent for Mobile only...
if(navigator.userAgent.match(/Mobile|Windows Phone|Lumia|Android|webOS|iPhone|iPod|Blackberry|PlayBook|BB10|Opera Mini|\bCrMo\/|Opera Mobi/i) ) {
console.log('Mobile Stuff...');
}
//User agent for Tablet only...
if (navigator.userAgent.match(/Tablet|iPad/i)) {
console.log('Tablet Stuff...');
}
//User-agent for Desktop only...
if(!navigator.userAgent.match(/Mobile|Windows Phone|Lumia|Android|webOS|iPhone|iPod|Blackberry|PlayBook|BB10|Opera Mini|\bCrMo\/|Opera Mobi|Tablet|iPad/i) ) {
console.log('Desktop Stuff...');
}

TA貢獻1893條經驗 獲得超10個贊
JS
我看到你的問題最簡單的解決方案是檢查 JS 值是否window.innerWidth
大于或等于 992px(最小桌面寬度)。
CSS
然而,由于您確實想要應用與 CSS 相關的樣式,您很可能想要編寫一個媒體查詢來完成您的工作。
例子:
@media screen and (min-width: 992px) { /* CSS-styling for desktop */ }
它們最好放置在 CSS 樣式表的底部。如果您不熟悉它們,我強烈建議您檢查一下。
- 3 回答
- 0 關注
- 136 瀏覽
添加回答
舉報