0

子组件:B

            <div className="cd-container" ref={this.props.cdContainerRef}>

父组件A

resizeListener=()=>{
        let cdPlayerRef = this.cdPlayerRef;
        //这里获取cdPlayerRef.top是0,我在想是不是B子组件还没渲染完成就进入这里面了所以获取不到?
        this.fastRewind.style.top = String(`${cdPlayerRef.offsetTop+260}px`);
        this.fastForward.style.top = String(`${cdPlayerRef.offsetTop+260}px`);
        this.bottomBarRef.style.top =         String(`${cdPlayerRef.offsetTop+320}px`);
    }
componentDidMount() {
    window.addEventListener('resize', this.resizeListener);
    this.resizeListener();
}
<B cdContainerRef={ref=>this.cdPlayerRef = ref}>

1 个回答

0

已经解决了,是微信浏览器的问题,国产浏览器n年不更新,现在chrome都60了,再不更新尽早步雅虎后尘