当前位置: 首页 > news >正文

如何实现图片垂直旋转90度的问题

 非常简单的问题,一串代码就可以解决。复制修改一下就可以直接使用,一个简单的小demo。写项目的时候需要写的功能,不到二十行代码就可以实现。

  1. <html>
    <head><title>旋转图片</title><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><meta name="viewport" content="initial-scale=1.0, user-scalable=no" /><style type="text/css">body, html{width: 100%;height: 100%;margin: 0;padding: 0;background-color: transparent;}/*包裹图片div样式*/#allDiv{font-family: "微软雅黑";font: 14px/1.8 arial;}/*图片样式*/.demoImg{background-color: Gray;border: none;margin-bottom: 50px;}.bottom{width: 100%;position: fixed;bottom: 10px;text-align: center;}.btn{cursor: pointer;width: 100px;height: 35px;background: rgba(38, 38, 38, 0.6);border: 0px;color: white;}</style>
    </head>
    <body><div id="allDiv" style="text-align: center;"><img id="demoImg" alt="图片" class="demoImg" src="https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1600861823902&di=29dac776c7336304cc69dc01983cc779&imgtype=0&src=http%3A%2F%2Fb-ssl.duitang.com%2Fuploads%2Fitem%2F201607%2F18%2F20160718205958_EzVsa.jpeg" /></div><div class="bottom"><div class="col-md-12 col-sm-12 col-xs-12 text-center"><button class="btn" type="button" onclick="SetImgRotate(0)" id="btnLeft">左旋转</button><button class="btn" type="button" onclick="SetImgRotate(1)" id="btnRight">右旋转</button></div></div><script type="text/javascript">//旋转图片var current = 0;function SetImgRotate(leftOrRight) {var img = document.getElementById('demoImg');if (leftOrRight == 0) {//左旋转current = (current - 90) % 360;}else if (leftOrRight == 1) {//右旋转current = (current + 90) % 360;}img.style.transform = 'rotate(' + current + 'deg)';}</script>
    </body>
    </html>


http://www.mrgr.cn/news/17533.html

相关文章:

  • HarmonyOS开发实战( Beta5版)应用滑动场景帧率问题分析最佳实践
  • IDEA插件开发中JavaProgramPatcher的使用
  • 【JUC】08-线程等待与唤醒
  • 搭建IPsec VPN隧道解决PLC设备与主控上位机无法使用公网IP进行通信的问题
  • [STM32]从零开始的STM32标准库环境搭建(小白向)
  • 【读书笔记-《30天自制操作系统》-13】Day14
  • Ai Illustrator 取消吸附到像素点,鼠标拖动的时候只能到像素点
  • pg 唯一性约束修复
  • ConcurrentHashmap面试【高频】
  • 家里装修如何选择五金件?听商家说还是信品牌
  • 经典大语言模型解读(2):生成式预训练的先锋GPT-1
  • MySQL基础操作
  • 第8讲 ,ISP 串口程序下载
  • 快速构建一个ui界面程序--pyqt入门
  • springboot 整合mongoDB
  • 简述线性表、栈和队列的异同
  • stm32开发之rt-thread使SysTick处于微妙级运行时,出现的问题记录
  • shell了解和问答机制
  • 学习周报-2024.8.31
  • 全国大学生数学建模竞赛系统使用手册