【问题标题】:How to get background location of modal window from previous page, like Unsplash did?如何从上一页获取模态窗口的背景位置,就像 Unsplash 一样?
【发布时间】:2020-11-07 14:02:26
【问题描述】:

Unsplash中模态窗口的背景页面真的很独特。

仿真:

  1. 点击来自 Feed 的照片
  2. 然后点击到模态页面上的另一张照片观看效果
  3. 刷新页面
  4. 在浏览器上点击返回
  5. 注意模态窗口背景位置的路线

所以我的问题是如何正确创建这个背景位置?

【问题讨论】:

    标签: reactjs react-redux react-router react-router-dom


    【解决方案1】:

    Ciao,我个人的观点是,当你返回时,Unsplash 页面会重新触发你之前打开的模态窗口。 Unspalsh 是用 React 编写的,例如,代码可能是这样的:

    function Page() {
      const [state, setState] = useState({...});
      useEffect(() => {
          // get data from cache
          if (data) {
            // (re)open dialog with photo
          }
      }, [state]); // state in deps so useEffect will be re-triggered each time you enter in Page
    }
    

    我不想简化,但这可能是一个起点。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-19
      • 1970-01-01
      相关资源
      最近更新 更多