猛跑小豬
2022-12-22 09:45:37
我正在使用以下代碼屏幕更大 999px<script> if ((window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth) >= 999) { // Show on screens bigger than 999px }</script>屏幕小于 767px<script> if ((window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth) < 767) { // Show on screens smaller than 767px }</script>現在我的目標是顯示 970 到 768 之間的東西我已經嘗試了下面的代碼,但這在 767px 以下也可見<script> if ((window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth) < 970) { // Show on screens from 970 till 768 }</script>我如何設置它只顯示在 970 到 768 的屏幕上?我不會使用 CSS。
2 回答

小怪獸愛吃肉
TA貢獻1852條經驗 獲得超1個贊
let width = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
if( width >=768 && width <= 970){
// Show on screens between 768 and 970 px
}
else if (width < 768){
// Show on screens smaller than 768px
}
else if (width > 970){
// Show on screens bigger than 970px
}
else {
// Show other cases
}
添加回答
舉報
0/150
提交
取消