前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >行走小动画案例扩展

行走小动画案例扩展

作者头像
小闫同学啊
发布2019-07-18 10:57:29
2280
发布2019-07-18 10:57:29
举报
文章被收录于专栏:小闫笔记小闫笔记
代码语言:javascript
复制
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        .box{
            border: 1px black solid;
            height: 180px;
            width: 120px;
            margin: 0 auto;
            position: relative;
            overflow: hidden;
        }
        .box img{
            position: absolute;
            left: 0px;
            top: 0px;
        }
        button{
            height: 30px;
            width: 30px;
            position:absolute ;
            top:200px;
            margin-top: 70px;
            left:50%;
            margin-left: -150px;
            border-radius: 50%;
            border: none;
            outline: none;
            font-size: 20px;
        }
        #butn2{
            top:200px;
            margin-top: 70px;
            left:50%;
            margin-left:100px;
        }
    </style>
    <script>
        window.onload = function(){
            var oImg = document.getElementById('img01');
            var num = 0;
            var speed = 120;
            var oTimer = null;
            oTimer = setInterval(fnMove,120)
            function fnMove(){
                num -= speed
                if(num<-860){
                    num = 0
                }
                if(num>0){
                    num = -840
                }
                oImg.style.left = num + 'px'
            }
            var oButn1 = document.getElementById('butn1')
            var oButn2 = document.getElementById('butn2')
            oButn1.onclick = function(){
                speed = 120
            }
            oButn2.onclick = function(){
                speed = -120
            }
            oImg.onmouseover = function(){
                clearInterval(oTimer)
            }
            oImg.onmouseout = function(){
                oTimer = setInterval(fnMove,120)
            }
        }
    </script>
</head>
<body>
    <img src="images/walking.png" alt="行走图片">
    <button id="butn1">&lt;</button>
    <div class="box">    
        <img src="images/walking.png" alt="行走图片" id="img01">      
    </div>
    <button id="butn2">&gt;</button>
</body>
</html>
本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2018-12-15,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 全栈技术精选 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
图像处理
图像处理基于腾讯云深度学习等人工智能技术,提供综合性的图像优化处理服务,包括图像质量评估、图像清晰度增强、图像智能裁剪等。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档