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

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

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

<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>


目录
相关文章
|
Android开发 芯片 异构计算
Android图形显示系统——下层显示4:图层合成下(硬件合成器)
硬件合成器-HwComposer 使用3D合成,需要大面积的像素混合计算和大量的内存传输(GPU读写GraphicBuffer所需),对GPU和DDR来说是一个巨大的负担。在GPU/DDR重度使用的场景(比如玩游戏),会造成发热、卡顿等。 为了提升性能,减少功耗,可以将合成这个过程交由另一个芯片完成,减轻GPU负担。进一步,直接让这个芯片连LCD,在LCD需要显示某一行时
7008 0
|
网络协议
免费的几款内网穿透工具
免费的几款内网穿透工具
12994 1
|
缓存 负载均衡 Java
Java分布式系统架构设计与实现
【4月更文挑战第2天】在快速发展的互联网时代,Java分布式系统成为应对复杂业务和高用户量的首选。通过服务化拆分、注册发现、负载均衡和缓存等技术,如Spring Cloud和Dubbo,开发者能构建高效、可靠、可扩展的系统。服务注册与发现确保服务间通信,负载均衡分配请求,分布式缓存如Redis提升性能。面对数据一致性和监控等挑战,Java提供工具解决,助力打造现代分布式应用。
818 2
Java分布式系统架构设计与实现
|
消息中间件 JSON Java
Spring Boot、Spring Cloud与Spring Cloud Alibaba版本对应关系
Spring Boot、Spring Cloud与Spring Cloud Alibaba版本对应关系
25295 0
|
存储 机器学习/深度学习 算法
python 五种算法转置后翻转、层次旋转、递归分块、一次性旋转、环状替换 实现旋转图像【力扣题48】
python 五种算法转置后翻转、层次旋转、递归分块、一次性旋转、环状替换 实现旋转图像【力扣题48】
|
负载均衡 Java API
|
安全 C语言
揭秘const的神奇之处
当我们提到const时,通常会想到它作为常量的用途。然而,实际上它的最大魅力在于可以修饰函数的参数和返回值。在本文中,我将为您揭开关于const的一些秘密。
121 0