老师帮忙看下代码,线路提示列表做动画显示该怎么弄

来源:8-11 自由编程

weixin_慕数据0318417

2019-12-26 01:22:28

<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">

    <meta http-equiv="X-UA-Compatible" content="ie=edge">

    <title>高德地图线路导航</title>

    <link rel="stylesheet" href="https://netdna.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">

    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.7.2/animate.min.css">

    <script type="text/javascript" src="https://webapi.amap.com/maps?v=1.4.15&key=598752f778bdf24aee04bbf081d10a1d&plugin=AMap.Autocomplete,AMap.Scale,AMap.ToolBar,AMap.ControlBar,AMap.MapType,AMap.Driving,AMap.Transfer,AMap.Riding,AMap.PlaceSearch"></script> 

    <style>

        #container {

            width: 100%;

            height: 100%;

            position: absolute;

            right: 0;

            top: 0;

        }

        #searchBox {

            width: 300px;

            position: absolute;

            left: 20px;

            top: 20px;

            background-color: #3d93fd;

            border-radius: 5px;

            text-align: center;

        }

        #searchResult {

            width: 300px;

            max-height: 380px;

            background-color: white;

            border: none;

            position: relative;

            overflow: scroll;

            /* display: none; */

        }

        #title {

            margin: 15px;

            color: white;

        }

        i {opacity: 0.5;

            margin: 10px;

            cursor: pointer;

            margin: 0 15px;

            padding: 5px;

        }

        i:hover {

            opacity: 0.75;

        }

        .search_ipt {

            position: relative;

            height: 30px;

            line-height: 30px;

            width: 250px;

            font-size: 14px;

            color: #acd7ff;

            background-color: #3587eb;

            border-radius: 2px;

            margin-bottom: 10px;

            margin-left: 25px;

            text-align: left;

        }

        label {

            padding: 0 0 0 10px;

        }

        input {

            width: 75%;

            font-size: 14px;

            line-height: 27px;

            color: #e1f1ff;

            border: none;

            text-indent: 5px;

            background: transparent;

            text-indent: 5px;

            outline: 0;

            caret-color:white;

        }


        input::-webkit-input-placeholder,

        textarea::-webkit-input-placeholder {

        /* WebKit browsers */

            color: #acd7ff;

        }

        input:-moz-placeholder,

        textarea:-moz-placeholder {

        /* Mozilla Firefox 4 to 18 */

            color: #acd7ff;

        }

        input::-moz-placeholder,

        textarea::-moz-placeholder {

        /* Mozilla Firefox 19+ */

            color: #acd7ff;

        }

        input:-ms-input-placeholder,

        textarea:-ms-input-placeholder {

        /* Internet Explorer 10+ */

            color: #acd7ff;

        }


        #searchBtn {

            background-color: #559ffb;

            color: white;

            border: none;

            height: 30px;

            margin: 10px 25px 20px 15px;

            padding: 0 20px;

            border-radius: 2px;

            box-shadow: 0 1px 1px 0 rgba(0,0,0,.21);

            cursor: pointer;

            float: right;

        }

    </style>

</head>

<body>

    <div id="container"></div>

    <div id="searchBox">

        <div id="title">

            <i class="fa fa-car" id="car"></i>

            <i class="fa fa-bus" id="bus"></i>

            <i class="fa fa-bicycle" id="bicycle"></i>

        </div>

        <div class="search_ipt">

            <label>起</label>

            <input id="start" type="text" placeholder="请输入起点">

        </div>

        <div class="search_ipt">

            <label>终</label>

            <input id="end" type="text" placeholder="请输入终点">

        </div>

        <div id="footer">

            <button id="searchBtn">开车去</button>

        </div>

        <div id="searchResult"></div>

    </div>

    <script>

        car.style.opacity = 1;

        var map = new AMap.Map('container',{

            zoom:10,

            center: [114.305215,30.592935],

        })

        new AMap.Autocomplete({

            input:start

        })

        new AMap.Autocomplete({

            input:end

        })


        var searchNode = new AMap.Autocomplete({

            input: 'start'

        })

        var placeSearch = new AMap.PlaceSearch({

            map: map,

            pageSize: 5,

            panel: 'searchResult'

        })

        AMap.event.addListener(searchNode,'select',function(e){

            map.setCenter(e.poi.location);

            map.setZoom(12);

            placeSearch.search(e.poi.name);

        })


        car.onclick = function(){

            car.style.opacity = 1;

            bus.style.opacity = 0.5;

            bicycle.style.opacity = 0.5;

            searchBtn.innerHTML = '开车去';

        }

        bus.onclick = function(){

            car.style.opacity = 0.5;

            bus.style.opacity = 1;

            bicycle.style.opacity = 0.5;

            searchBtn.innerHTML = '坐公交';

        }

        bicycle.onclick = function(){

            car.style.opacity = 0.5;

            bus.style.opacity = 0.5;

            bicycle.style.opacity = 1;

            searchBtn.innerHTML = '骑车去';

        }


        searchBtn.onclick = function(){

            map.clearMap();

            searchResult.innerHTML = '';

            map.getCity(function (data) {

                var city = data.city;

                if (data.city == '') {

                    city = data.province;

                }

                if (searchBtn.innerHTML == '开车去') {

                    new AMap.Driving({

                        map: map,

                        panel: 'searchResult'

                    }).search([

                        {keyword:start.value},

                        {keyword:end.value},

                    ],function(status,data){});

                }

                else if (searchBtn.innerHTML == '坐公交') {

                    new AMap.Transfer({

                        map: map,

                        panel: 'searchResult'

                    }).search([

                        {keyword:start.value,city:city},

                        {keyword:end.value,city:city},

                    ],function(status,data){});

                }

                else if (searchBtn.innerHTML == '骑车去') {

                    new AMap.Riding({

                        map: map,

                        panel: 'searchResult'

                    }).search([

                        {keyword:start.value},

                        {keyword:end.value},

                    ],function(status,data){});

                }

            })

            searchResult.classList.add('animated', 'slideInDown');

        }

    </script>

</body>

</html>


写回答

2回答

_是你_

2019-12-26

找了一下官网,好像没有这个事件。我加了一个定时器效果就有了,你康康。要是不行的话就把定时器的时间改长一点再试试。还有这个是高德的官网文档,你也可以自己查查https://lbs.amap.com/api/javascript-api/guide/abc/plugins

http://img.mukewang.com/climg/5e044f0a0958930e06020086.jpg


0

weixin_慕数据0318417

提问者

2019-12-26

地图上的线路加载完成时有监听事件吗?该怎么使用

0

0 学习 · 6815 问题

查看课程