css 图片旋转并自适应div

论坛 期权论坛 编程之家     
选择匿名的用户   2021-6-2 17:46   2285   0
import { useState} from 'react'
function zimg(params) {
    const [rotateIndex,setrotateIndex]=useState(0)
    function bindrotate(){
        let rotateIndex1=rotateIndex?0:1
        setrotateIndex(rotateIndex1)
    }
      return (
 <>
<div className={` ${styles.box_img} ${rotateIndex?styles.box_rotate:''}`}>
    <img src="/img/1.png">
</div>
<div className={styles.box_btn} onClick={bindrotate}>旋转<div>
</>
       )
}
export default zimg
.box_img{
    width: 100vw;
 height: 100vh;
 overflow: hidden;
}
//旋转90度,宽度和高度调换位置,并调整中心位置
.box_rotate{
  overflow: hidden;
  transform: rotate(90deg)  translate(calc( 100vh / 2 - 100vw / 2) , calc(100vh / 2 - 100vw / 2));
  width: 100vh;
  height: 100vw;
    transform-origin: center;
}

 .box_btn{
  position: fixed;
  left: 0;
  bottom: 0;
  width: 100%;
  height: 40px;
  line-height: 40px;
  background: rgba(0,0,0,0.5);
  color: #ffffff;
 }

css 图片旋转并自适应div,html的,可以直接运行 https://download.csdn.net/download/qq_41211900/16077801

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP