js动画案例

js动画的三个基础案例

协议按钮

<textarea name="" id="" rows="10" cols="20">
        协议内容,没有用
    </textarea>
    <button disabled>请仔细阅读以上协议(5)</button>
var button = document.getElementsByTagName('button')[0]
    var num = 5
    var timer = setInterval(function () {
        num--
        // button.innerHTML = "请仔细阅读以上协议(" + num + ")"
        button.innerHTML = `请仔细阅读以上协议(${num}`
        if (num <= 0) {
            clearInterval(timer)
            button.innerHTML = "同意"
            button.disabled = false
        }
    }, 1000)
    button.onclick = function () {
        console.log('测试');
    }

手机验证码

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        button {
            width: 200px;
            height: 50px;
            background-color: aquamarine;
            border: 0;
            font-size: 25px;
            color: white;
        }
    </style>
</head>

<body>
    <button>获取验证码</button>
</body>


var button = document.getElementsByTagName('button')[0]

    button.addEventListener('click', function () {
        var num = 6
        // console.log('测试');
        // console.log(this);
        var that = this
        // this.innerHTML = num
        var timer = setInterval(function () {
            // console.log(that);
            num--
            that.disabled = true
            that.innerHTML = num
            if (num <= 0) {
                that.disabled = false
                that.innerHTML = '重新获取'
                clearInterval(timer)
            }
        }, 1000)
    })

物体渐变

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #box {
            width: 400px;
            height: 400px;
            background-color: red;
            /* opacity: 0.5; */
        }
    </style>
</head>

<body>
    <div id="box"></div>
</body>

var box = document.getElementById('box')
    var opactiveStyle = 10
    box.onmouseenter = function () {
        // var timer = setInterval(() => {
        //     console.log(this);
        //     // this.style.opacity = 0
        // }, 100)
        var that = this
        var timer = setInterval(function () {
            opactiveStyle--
            // console.log(opactiveStyle);
            that.style.opacity = opactiveStyle / 10
            if (opactiveStyle <= 0) {
                clearInterval(timer)
            }
        }, 100)
    }
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个基于 ArcGIS JavaScript API 4.x 实现移动轨迹动画的示例代码: ```javascript require([ "esri/Map", "esri/views/MapView", "esri/Graphic", "esri/geometry/Point", "esri/layers/GraphicsLayer", "esri/symbols/SimpleMarkerSymbol", "esri/symbols/SimpleLineSymbol", "esri/geometry/Polyline", "esri/geometry/support/webMercatorUtils", "dojo/domReady!" ], function(Map, MapView, Graphic, Point, GraphicsLayer, SimpleMarkerSymbol, SimpleLineSymbol, Polyline, webMercatorUtils) { // 定义起点和终点的经纬度坐标 var startPoint = [-122.414, 37.776]; var endPoint = [-122.426, 37.776]; // 创建地图和地图视图 var map = new Map({ basemap: "streets-navigation-vector" }); var view = new MapView({ container: "viewDiv", map: map, center: startPoint, zoom: 14 }); // 创建图形图层,并添加到地图中 var graphicsLayer = new GraphicsLayer(); map.add(graphicsLayer); // 创建起点和终点的点图形,并添加到图形图层中 var startSymbol = new SimpleMarkerSymbol({ color: "green", size: "8px" }); var endSymbol = new SimpleMarkerSymbol({ color: "red", size: "8px" }); var startPointGraphic = new Graphic({ geometry: new Point({ longitude: startPoint[0], latitude: startPoint[1] }), symbol: startSymbol }); var endPointGraphic = new Graphic({ geometry: new Point({ longitude: endPoint[0], latitude: endPoint[1] }), symbol: endSymbol }); graphicsLayer.addMany([startPointGraphic, endPointGraphic]); // 创建轨迹线的符号,并添加到图形图层中 var lineSymbol = new SimpleLineSymbol({ color: "blue", width: 4 }); var polylineGraphic = new Graphic({ geometry: new Polyline(), symbol: lineSymbol }); graphicsLayer.add(polylineGraphic); // 计算移动轨迹的点集合 var points = []; for (var i = 0; i <= 100; i++) { var lon = startPoint[0] + (endPoint[0] - startPoint[0]) * i / 100; var lat = startPoint[1] + (endPoint[1] - startPoint[1]) * i / 100; points.push([lon, lat]); } // 定义当前移动到的点的索引 var currentIndex = 0; // 定义移动函数,每隔一段时间移动到下一个点 function move() { polylineGraphic.geometry.addPath(points.slice(currentIndex, currentIndex + 2)); currentIndex += 1; if (currentIndex < points.length - 1) { setTimeout(move, 50); } } // 将经纬度坐标转换为 WebMercator 坐标系 points = points.map(function(point) { return webMercatorUtils.geographicToWebMercator(new Point({ longitude: point[0], latitude: point[1] })); }); // 开始移动 move(); }); ``` 在这个示例代码中,我们首先创建了一个地图和地图视图,并在地图上添加了一个图形图层。然后,我们创建了起点和终点的点图形,并将它们添加到图形图层中。接着,我们创建了轨迹线的符号,并将其添加到图形图层中。接下来,我们计算了移动轨迹的点集合,并定义了一个移动函数,每隔一段时间移动到下一个点。最后,我们将经纬度坐标转换为 WebMercator 坐标系,并开始移动。 需要注意的是,该示例代码中的移动函数仅是一个简单的实现,实际应用中可能需要更加复杂的实现,例如根据实时数据更新移动轨迹等。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值