开心一笑: 会买水果的狗狗

    关注微信公众号

    QQ群:831045818

    app下载

    当前位置:首页> React > 技术文档 > 正文
    react AntDesign Carousel 高度自动处理
    发布时间:2019-11-11 16:54:15.0 浏览次数:
    componentDidMount() {
    
        setTimeout(() => {
            this.getPicHeight("0","details_photoArr")
        }, 500);
    }
    
    //解决幻灯图片加载
    getPicHeight=(index,id)=>{
        var height=0;
        var width=0;
        if(isNaN(index)){
            index=0;
        }
        var path =$("#"+id+index).attr("src")
        if(String(path) != "undefined"){
            var w_width=Number(document.body.clientWidth);
            var nImg = new Image();
            nImg.src = path;
            nImg.onload = function () {
                var w = nImg.width;
                if(w > w_width){
                    height=(w_width/w)*(nImg.height);
                    width=w_width;
                }else {
                    height=nImg.height;
                    width=nImg.width;
                    console.log("图片小"+ nImg.height+" path:"+path)
                }
                $("#"+id+" .slider-list").css({"height":height+"px"})
                $("#"+id+" .slider-slide").css({"background":"#fff"})
                $("#"+id+index).css({"height":height+"px","width":width,"margin":"auto","display":"block"})
                // console.log("height:"+height+" w:"+(w/w_width) +" w_:"+nImg.width +" h:"+nImg.height)
            }
        }
    }
    
    //DOM ID 并且幻灯加上 afterChange事件
    <p id="details_photoArr">
            <Carousel autoplay ={false} infinite={true}  afterChange={index => this.getPicHeight(index,"details_photoArr")}>
    
                {this.state.photoArr ? this.state.photoArr.map(((v, index)=>(
                        <img  className={styles.banner_pic}
                              src={v}
                              id={"details_photoArr"+index}
                              alt=""
                              style={{verticalAlign: 'top',"margin":"auto" }}
                              className={styles.arr_pic}
                        />
                    )))
    
                    :''}
            </Carousel>
    </p>


    关注"都市百货" 了解南陵

    微信咨询wanglf2r(不拉群 发广告者勿加)

    0
    0
    上一篇:react 循环遍历数据 上一篇:南陵目连戏入围国家级非遗推荐名单

    评论已有0

    提交评论

    热门评论

    南陵新闻
    公示公告
    常用查询
    风光南陵
    走出南陵
    友情链接