簡體   English   中英

我需要使用React.JS水平滾動到div id嗎?

[英]I need to horizontally scroll to a div id using React.JS ?

scrollFunc()
{    
     document.getElementById("myID").scrollIntoView({"block":"center"})    
}

我嘗試了scrollIntoView({“ block”:“ center”})在chrome中可以正常使用,但是Internet Explorer上有問題!

scrollIntoView在IE / Edge中具有部分支持。

IE / Edge不支持scrollIntoView({"block":"center"})


  • 您有一個選項scrollIntoView(true)對應於

scrollIntoView({block: "start", inline: "nearest"})

  • 您有選項scrollIntoView(false)對應於

scrollIntoView({block: "end", inline: "nearest"})


如果需要{"block":"center"}我建議使用其他API或方法。

在此處了解更多信息。

https://developer.mozilla.org/zh-CN/docs/Web/API/Element/scrollIntoView https://caniuse.com/#search=scroll

試試看

要獲取頁面中任何元素的位置,您可以像這樣使用'getBoundingClientRect'方法,並使用window.scrollTo()滾動到該特定位置。

var htmlElement = document.getElementById('container'); var elementPosition = element.getBoundingClientRect() window.scrollTo(elementPosition.left, 0)

另請參閱此鏈接以獲取更多信息: https : //developer.mozilla.org/zh-CN/docs/Web/API/Element/getBoundingClientRect

在中使用.map<div> 標簽-react.js</div><div id="text_translate"><p> 我真的很感激任何幫助。 所以該項目是一個反應項目。</p><p> 這是我獲取<a href="https://i.stack.imgur.com/WelCP.png" rel="nofollow noreferrer">的內容:獲取請求</a></p><p>這是我從服務器響應的內容: <a href="https://i.stack.imgur.com/e2QG3.png" rel="nofollow noreferrer">Response from server</a></p><p> 我試了一下 Postman,看看我收到的是什么類型的 json。 這是它返回的內容: <a href="https://i.stack.imgur.com/yg6IE.png" rel="nofollow noreferrer">Postman 測試</a></p><p>我遇到的問題是我無法 map 收到的數據。 一旦輸入鏈接,我只想在首頁上以一種很好的方式顯示接收到的數據。</p><p> 是否可以將 map 放在 div 標簽內? 或者還有另一種方法嗎?</p><p> <em><strong>請注意該項目是作為功能組件編寫的</strong></em></p></div>

[英]Using .map in <div> tag - react.js

暫無
暫無

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

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