【发布时间】:2018-03-19 02:38:43
【问题描述】:
在我的响应式网络应用中调整窗口大小后,我无法让视频播放器持续播放。我正在使用 react-responsive 库来帮助解决这个问题。我有一个不同的 MediaQuery 元素处理我的外部“内容”组件中的每个窗口大小范围,该组件使用 antd 布局组件处理整个页面布局,所以我猜测正在发生的事情是组件的不同部分显示每个范围,导致每次检测到新范围时视频也会“重置”。 (当我删除媒体查询时,问题就消失了。)
如何做到这一点,以便当视频播放器当前正在播放视频(这是一个渲染 api 资源的 iframe)时,它继续通过一个窗口调整到不同的范围来播放?我猜我可以更改媒体查询范围并以某种特定方式嵌套它们,但我不知道该怎么做。
内容组件中的页面布局:
const Inside = props => (
<Layout.Content
style={{
background: '#fff',
padding: '10px 10px',
width: props.width,
margin: '0 auto 50px',
}}
>
<main>
<Route exact path="/" component={Home} />
<Route path="/quicklooks" component={Quicklooks} />
<Route path="/features" component={Features} />
<Route path="/bombcasts" component={Bombcasts} />
</main>
</Layout.Content>
);
const Content = () => (
<div>
<XS><Inside width="100%" /></XS>
<SM><Inside width="100%" /></SM>
<MD><Inside width="740px" /></MD>
<LG><Inside width="940px" /></LG>
<XL><Inside width="1160px" /></XL>
<XXL><Inside width="1160px" /></XXL>
</div>
);
视频播放器:
const CurrentVideo = (props) => {
const pubDateFormatted = Moment(props.pub_date).format('MMM. D, YYYY h:mma');
return (
<div style={{ background: '#000', margin: '0 auto', width: '100%' }}>
<Row type="flex" justify="center">
<Col xs={24} lg={8}>
<div style={{ padding: '16px', color: '#fff' }}>
<h2 style={{ color: '#fff' }}>{props.name}</h2>
<p><i> Posted by {props.user} | {pubDateFormatted}</i></p>
<p>{props.deck}</p>
</div>
</Col>
<Col xs={24} lg={16} >
<div className="intrinsic-container intrinsic-container-16x9">
<iframe
frameBorder={0}
allowFullScreen
title={props.name}
src={props.embed_player}
/>
</div>
</Col>
</Row>
</div>
);
};
CurrentVideo.propTypes = {
name: PropTypes.string.isRequired,
user: PropTypes.string.isRequired,
pub_date: PropTypes.string.isRequired,
deck: PropTypes.string.isRequired,
embed_player: PropTypes.string.isRequired,
};
export default CurrentVideo;
设置为特定窗口宽度的不同媒体查询:
export const XXL = props => (
<Responsive minWidth={1600}>
{props.children}
</Responsive>
);
export const XL = props => (
<Responsive minWidth={1200} maxWidth={1599}>
{props.children}
</Responsive>
);
export const LG = props => (
<Responsive minWidth={992} maxWidth={1199}>
{props.children}
</Responsive>
);
export const MD = props => (
<Responsive minWidth={768} maxWidth={991}>
{props.children}
</Responsive>
);
export const SM = props => (
<Responsive minWidth={576} maxWidth={767}>
{props.children}
</Responsive>
);
export const XS = props => (
<Responsive maxWidth={575}>
{props.children}
</Responsive>
);
【问题讨论】:
标签: reactjs responsive-design antd