当前位置: 首页 > Web前端 > HTML5

图片轮播预览

时间:2023-04-05 21:08:24 HTML5

效果实现js代码:importReact,{Component}from'react';从'nuka-carousel'导入旋转木马;导入“./largePreview.scss”;constIndex=props=>{返回props.visible?<大特权{...props}/>:null;};/***@param{Array}pics图片数组[{img:''},{img:''}]*@param{boolean}visible是否显示大图图片预览*@param{number}currentIndex为当前图片编号,数组下标*@param{function}close关闭当前图片预览*/classLargePriviewextendsComponent{constructor(props){super(props);this.state={screenHeight:'100%',currentIndex:1,toggleBarHeight:0,pics:[]};}componentWillMount=()=>{if(navigator.userAgent.indexOf('cheshangtong')>-1){this.setState({pics:JSON.parse(WBCST.getParamFromUrl('pic')),currentIndex:Number(WBCST.getParamFromUrl('index'))});}else{this.setState({图片:this.props.location.param.pic,currentIndex:this.props.location.param.index});}WBCST.toggleTitlePanel({hideNavBar:true,bounces:0,statusBarStyle:'light'},data=>{this.setState({toggleBarHeight:data.toggleBarHeight});});};componentDidMount(){constscreenHeight=(document&&document.body.clientHeight)||'100%';this.setState({screenHeight});}screenHeight=()=>{constscreenHeight=(document&&document.body.clientHeight)||'100%';让clientWidth=document.querySelector('body').offsetWidth;const{toggleBarHeight}=this.state;让height=toggleBarHeight>50?toggleBarHeight:toggleBarHeight+(45/375)*clientWidth;返回screenHeight-高度;};handleImgClick(show,index){this.setState({currentIndex:index});}handleTop=()=>{const{toggleBarHeight}=this.state;让clientWidth=document.querySelector('body').offsetWidth;让top=toggleBarHeight>50?toggleBarHeight-(45/375)*clientWidth:toggleBarHeight;返回顶部;};render(){const{screenHeight,currentIndex,pics}=this.state;返回(float">{if(navigator.userAgent.indexOf('车商通')>-1){WBCST.closeCurrentPage();}else{this.props.history.go(-1);}}}>

{currentIndex+1}/{pics.length}
{this.handleImgClick(true,index);}}>{pics.map((imgItem,imgIndex)=>{return(
);})});}}exportdefaultLargePriview;css代码:$baseFontSize:32px!default;//像素到rems@functionpxToRem($px){@return$px/$baseFontSize*1rem;}.imgs-large-wrapper{高度:100%;宽度:100%;背景:#000000;溢出:隐藏;.pre-status{背景:#000000;}.imgs-top-float{宽度:100%;高度:pxToRem(88px);显示:弹性;对齐项目:居中;填充:0pxToRem(30px);弹性方向:行;证明内容:空格之间;.close{背景:url('./../../img/close.png');背景重复:不重复;背景大小:100%;宽度:pxToRem(60px);高度:pxToRem(60px);}.imgs-index-style{宽度:100%;字体大小:pxToRem(34px);字体系列:PingFang-SC-Bold,PingFang-SC;颜色:#FFFFFF;文本对齐:居中;}.right{宽度:pxToRem(60px);}}.imgs-carousel-box{宽度:100%;显示:弹性;对齐项目:中心r;证明内容:居中;img{宽度:100%;}}}