uni-app獲取dom節點信息簡單說明


<view id="iamnode">我是節點<view>

mounted() {  //獲取節點信息,最好在mounted之后獲取以確保獲取到
    let theNode=uni.createSelectorQuery().select("#iamnode")
    theNode.boundingClientRect((data)=>{
          console.log(data)
    }).exec()
},


注:支持以下選擇器
ID選擇器:#the-id
class選擇器(可以連續指定多個):.a-class.another-class
子元素選擇器:.the-parent > .the-child
后代選擇器:.the-ancestor .the-descendant
跨自定義組件的后代選擇器:.the-ancestor >>> .the-descendant
多選擇器的並集:#a-node, .some-other-nodes

注:uniapp目前未發現有效的方法來通過js操作一些dom。比如實現簡單的動畫效果的需求。
可以通過另外的思路,見:https://www.cnblogs.com/huihuihero/p/14871075.html

詳細文檔請移步至: https://uniapp.dcloud.io/api/ui/nodes-info


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM