2 liu nian Liu_Nian_ 于 2017.11.15 13:26 提问

在一个纯js中用定时器改变线条的颜色使其达到闪烁的效果 10C
 导入高德地图并在页面中画了一条线,现在要用定时器改变线条的颜色,自己写的没有达到效果,完整页面代码如下:

<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
    <title>编辑折线、多边形、圆</title>
    <link rel="stylesheet" href="http://cache.amap.com/lbs/static/main1119.css"/>
    <script src="http://webapi.amap.com/maps?v=1.4.1&key=您申请的key值&plugin=AMap.PolyEditor,AMap.CircleEditor"></script>
    <script type="text/javascript" src="http://cache.amap.com/lbs/static/addToolbar.js"></script>
</head>
<body>
<div id="container"></div>

<script>

    var editorTool, map = new AMap.Map("container", {
        resizeEnable: true,
        center: [116.40, 39.90],//地图中心点
        zoom: 13 //地图显示的缩放级别
    });
    //在地图上绘制折线
    var editor={};
    editor._line=(function( ){
        var lineArr = [
            [116.37, 39.91],
            [116.38, 39.90],
            [116.39, 39.91],
            [116.39, 39.90]
        ];
        return new AMap.Polyline({
            map: map,
            path: lineArr,
            strokeColor: "#FF33FF",//线颜色
            strokeOpacity: 1,//线透明度
            strokeWeight: 3,//线宽
            strokeStyle: "solid"//线样式
        });
    })();

    map.setFitView();



debugger
  var colorindex=0;
setTimeout("showColor()", 10000);
   function showColor() {//改变颜色的方法
   var colorarray=new Array('#FF33FF','#FF8C00','#EE00EE','#C0FF3E','#98FB98','#8B2500');
   debugger

   colorindex++;
   debugger
   this.editor._line.F.strokeColor=colorarray[colorindex];
map.setFitView();
   setTimeout("showColor()", 10000);
    }
</script>
</body>
</html>

1个回答

airfling
airfling   2017.11.15 14:08

下民这部分代码需要重新获取到dom对象

 this.editor._line.F.strokeColor=colorarray[colorindex];
map.setFitView();
Liu_Nian_
Liu_Nian_ 请问该怎么改
7 天之前 回复
Csdn user default icon
上传中...
上传图片
插入图片