繁体   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