javascript - 如何从div[html+jquery]获取文本

标签 javascript jquery html css

我正在为我的目的更改动画代码,但无法从 div 中获取文本来为其设置动画。

原创动画: https://codepen.io/Lunoware/pen/gjYjBw

我的代码(我删除了脚本的输入、输入部分和“if”指令)

<div class="container">
  <div class="row">
    <p id="text">Test</p>
  </div>
</div>

CSS

@background: #0bc020;


  #text{
    font-size: 2.5em;
    font-weight: bold;
    transition-duration: 1.5s;
    .char-outer-space{
      position: relative;
      display: inline-block;
      width: 20px;
      height: 20px;
    }
    .char-outer{
      position: relative;
      display: inline-block;
      width: 20px;
      height: 20px;
      margin: 5px;
      .char-inner{
        position: absolute;
        animation-name: jumping;
        animation-duration: 0.5s;
        animation-iteration-count: infinite;
        animation-direction: alternate;
        left:0px;
        top:-15px;
      } 
    }
  }
}

@keyframes jumping {
    from {
      transform: translate(0, 8px);
    }
    to {
      transform: translate(0, -0px);
    }
}

j查询

jQuery(document).ready(function(){
      function splitHtmlString(text){

        var string = '#text';  

        var charArr = string.split("");
        var fixedString = "";
        charArr.forEach(function(char, index) {

          var offset = -index/10;

          if(char != " "){
            fixedString += "<span class='char-outer' style='animation-delay:" + offset + "s;'><span class='char-inner' style='animation-delay:" + offset + "s;'>" + char + "</span></span>";
          }else{
            fixedString += "<span class='char-outer-space'></span>";
          }
        });

        $("#text").html(fixedString);
      }
      splitHtmlString("");
    });

我需要从 div 中获取文本的行

最佳答案

您可以在 W3schools 中找到更多引用资料

//get value as html
$('#text').html()
//get value as text  
$('#text').text()

关于javascript - 如何从div[html+jquery]获取文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56914159/

相关文章:

jquery - 当调用另一个元素的悬停事件时调用另一个元素的悬停事件

jquery - 滚动到 DIV 的垂直中间

html - CSS:基于基线的绝对位置文本?

html - 淡入和脉冲文本,暂停,然后循环淡出 CSS3 关键帧?

javascript - 如何在 Windows 8/Cordova 应用程序中打开本地 PDF?

javascript - 查找阿基米德螺线上某个点的 x,y 坐标

javascript - 加入2个输入Jquery?

jquery - 改变不同李的类(class)

Javascript onclick视频对象自动启动true

javascript - AngularJS 未捕获引用错误 : ng-repeat ng-click