HTML里使图片放大,旋转

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no">
    <title>Baidu</title>
    <style type="text/css">
        * {
            margin: 0;
            padding: 0;
        }

        li {
            list-style: none;
        }

        .top {
            width: 640px;
            height: 34px;
            margin: 64px auto;
        }

        .top span {
            width: 540px;
            height: 34px;
            position: relative;
            float: left;
        }

        /* 搜索输入框 */
        .top input {
            width: 540px;
            height: 34px;
            font-size: 18px;
        }

        /* 相机小图片,父元素.top span */
        .top img {
            position: absolute; /* 父元素position: relative,这里的position: absolute相对父元素绝对定位 */
            right: 8px; /* 定位到父元素span的右边,并且离右边8px */
            top: 50%; /* 离父元素span的上面一半的距离,父元素span的高除以2,结果:34/2 = 17px */
            margin-top: -12px; /* 上移12px,居中 */
            width: 24px;
            height: 24px;
        }

        /* 百度一下 */
        .top button {
            width: 100px;
            height: 38px;
            font-size: 16px;
        }

        .top input:hover {
            transform: scale(1.5, 1.5); /* 放大1.5倍 */
        }

        .top img:hover {
            transform: scale(1.2, 1.2); /* 放大1.2倍 */
        }

        .top button:hover {
            transform: scale(2, 2); /* 放大2倍 */
            color: red;
        }

        .bottom {
            width: 720px;
            height: 272px;
            margin: 64px auto;
        }

        .bottom ul {
            width: 720px;
            height: 144px;
        }

        .bottom ul li {
            float: left;
            width: 128px;
            height: 128px;
            padding: 8px;
        }

        .bottom ul li img {
            width: 128px;
            height: 128px;
        }

        /* 顺时针旋转360度 */
        @keyframes rotate360_1 {
            from {
                transform: rotate(0deg);
            }
            to {
                transform: rotate(360deg);
            }
        }

        /* 逆时针旋转360度 */
        @keyframes rotate360_2 {
            from {
                transform: rotate(0deg);
            }
            to {
                transform: rotate(-360deg);
            }
        }

        .bottom ul li:nth-child(1):hover {
            animation: rotate360_1 4s linear;
        }

        .bottom ul li:nth-child(2):hover {
            animation: rotate360_2 4s linear;
        }

        .bottom ul li:nth-child(3):hover {
            transform: scale(1.5, 1.5);
        }

        .bottom ul li:nth-child(4):hover {
            transform: skew(0deg, 50deg); /* 倾斜50度 */
        }
    </style>
</head>
<body>
<div class="top">
    <span>
        <input type="text" name=""/><img src="camera_off.png">
    </span>
    <button>百度一下</button>
</div>

<div class="bottom">
    <ul>
        <li><img src="top1.jpg"></li>
        <li><img src="top2.png"></li>
        <li><img src="top3.png"></li>
        <li><img src="top4.jpg"></li>
        <li><img src="top5.jpg"></li>
    </ul>
    <ul>
        <li><img src="bottom1.jpg"></li>
        <li><img src="bottom2.jpg"></li>
        <li><img src="bottom3.jpg"></li>
        <li><img src="bottom4.png"></li>
        <li><img src="bottom5.png"></li>
    </ul>
</div>
</body>
</html>
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要实现图片放大缩小和旋转功能,可以使用HTML5的canvas和JavaScript来实现。以下是一个简单的示例代码: HTML部分: ```html <canvas id="myCanvas"></canvas> ``` JavaScript部分: ```javascript var canvas = document.getElementById("myCanvas"); var ctx = canvas.getContext("2d"); // 创建一个图片对象 var img = new Image(); img.src = "image.jpg"; // 等待图片加载完成后再进行绘制 img.onload = function() { // 绘制图片 ctx.drawImage(img, 0, 0, canvas.width, canvas.height); }; // 定义变量用于存储图片的缩放比例和旋转 var scale = 1; var angle = 0; // 定义函数用于改变缩放比例和旋转 function zoomIn() { scale += 0.1; drawImage(); } function zoomOut() { scale -= 0.1; drawImage(); } function rotateLeft() { angle -= Math.PI / 6; drawImage(); } function rotateRight() { angle += Math.PI / 6; drawImage(); } // 定义函数用于绘制图片 function drawImage() { ctx.clearRect(0, 0, canvas.width, canvas.height); ctx.save(); ctx.translate(canvas.width / 2, canvas.height / 2); ctx.rotate(angle); ctx.scale(scale, scale); ctx.drawImage(img, -img.width / 2, -img.height / 2); ctx.restore(); } // 绑定按钮的点击事件 document.getElementById("zoom-in").addEventListener("click", zoomIn); document.getElementById("zoom-out").addEventListener("click", zoomOut); document.getElementById("rotate-left").addEventListener("click", rotateLeft); document.getElementById("rotate-right").addEventListener("click", rotateRight); ``` 在上面的代码中,我们首先创建了一个canvas元素,并获取了它的上下文对象ctx。然后,我们创建了一个Image对象img,并设置它的src属性为要加载的图片的URL。我们在img的onload事件中绘制了图片。然后,我们定义了四个函数用于改变缩放比例和旋转,以及一个drawImage函数用于绘制图片。在drawImage函数中,我们使用了canvas的变换函数translate、rotate和scale来实现图片的缩放和旋转。 最后,我们绑定了四个按钮的点击事件,分别调用对应的函数来改变缩放比例和旋转

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值