reactjs - 如何使用不影响主页的YouTube视频创建弹出窗口?

标签 reactjs youtube youtube-api video-streaming popupwindow

我正在尝试使用不影响主页的YouTube视频弹出窗口。

当您单击“跟踪”时,我仍然可以与主页交互,类似于this网站上的右下角的弹出视频。

我的YouTube API有App.js

{     
  getYouTubeApi = (searchTerms1, searchTerms2) => {
    fetch(`https://www.googleapis.com/youtube/v3/search?part=snippet&maxResults=10&q=${searchTerms1} ${searchTerms2}&type=video&key=YOUR_KEY`)
    .then(res=>res.json())
    .then(data=>{
      this.setState({videoId: data.items[0].id.videoId})
    })
  .catch(error=>console.log(error))
  }

render(){
  return (<YouTube opts={opts} videoId={this.state.videoId} />)
  }
}
getYouTubeApi函数,我单击的是单击轨道,该轨道刚刚到达YouTube视频加载页面的顶部。

Here是我的学校项目。

最佳答案

因为这比对业务逻辑更能描述DOM行为,所以您可以将所需的任何内容放入行为类似于模式的特定组件中(无论是换出css类还是根据某些条件设置内联样式)。

为了使该模式可重用,建议您将其设置为higher order component,以包装<Youtube />组件或要使用模式显示的任何其他组件。

例如,您可能有

const Modal = (ComponentToDisplayAsModal, props) => (
  <div class="modal">
   <ComponentToDisplayAsModal {...props} />
  </div>
)

然后,您可以将modal类的样式设置为类似于模式。

在要显示模态的 View 上,可以渲染
Modal(Youtube, props)

关于reactjs - 如何使用不影响主页的YouTube视频创建弹出窗口?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45683816/

相关文章:

javascript - 使用自定义数据属性处理事件或将数据绑定(bind)到处理程序?

javascript - Youtube iframe 视频在模态框关闭后重新启动

ios - 使用 YouTube API 从 youtube 查询中排除受限视频

api - 为什么对我的 YouTube API 调用进行的这个小更改不起作用?

javascript - 访问 localstorage 中的 `access_token` 属性

reactjs - 导入react-bootstrap组件测试失败

javascript - ReactJS + JavaScript : How to parse array into a new array?

api - YouTube Google 数据 API (GDATA) 是否已弃用?

jquery - 在自定义按钮中播放位于iframe中的youtube视频

ios - 访问未配置的 YouTube API