簡體   English   中英

當屏幕寬度小於不工作的數量時更改文本

[英]Change text when screen width is less than amount not working

當屏幕尺寸小於 650 時,我試圖更改此網站上的文本,但它不起作用。 我已經嘗試了Do something if screen width is less than 960 pxResizing images when screen is less than 1024 pixel width的答案,但沒有用。 是replit的鏈接,代碼片段也在下面。

if ($(window).width() < 650) { // I've also tried (window).width() and window.width
var words = $('.words');
words.text("Hello! This is the new text!");
}
else { 
}


<div class="intro">
  <div>
    <h1 class="ele">Hey there!</h1>
    <p class="ele words">Hi! This is the old text."</p>
  </div>
  <img class="ele me" src="me.png" alt="A picture of myself.">
</div>

我在 CodePen 上嘗試了您的代碼,它似乎工作正常,也許您的腳本加載到了錯誤的位置,或者您嘗試更改的元素尚未創建,也許更多的代碼可以幫助查看示例

<div class="intro">
  <div>
    <h1 class="ele">Hey there!</h1>
    <p class="ele words">Hi! This is the old text."</p>
  </div>
  <img class="ele me" src="me.png" alt="A picture of myself.">
</div>
$(window).resize(function() {
  if ($(window).width() < 650) {
    var words = $('.words');
    words.text("Hello! This is the new text!");
    }
    else { 
      var words = $('.words');
    words.text("Hello! This is the old text.");
  }
})

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM