Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
176 views
in Technique[技术] by (71.8m points)

javascript - How to highlight item on hover?

I′m integrating a Google Maps in an AngularJS 1.0.7 website. I have a list of items with pictures. In the other hand each item is displayed with an infoWindow in the map. What I want to do is when the user move the mouse over the picture the map should highlight that specific item. I don′t know what is the "Angular way" to do this.

I attach a plunker as starting point: https://plnkr.co/edit/qgfMldJ53N0iKnlsguMF?p=preview

Some code (better see plunker):

<ul>
   <li ng-repeat="car in cars">
        {{car.id}}: {{car.price}} (please, highlight the infoWindow in map onmouseover)
      </li>
    </ul>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can use ng-mouseover to flag the car to highlight

<ul>
   <li ng-repeat="car in cars" ng-mouseover="car.highlight = true">
      {{car.id}}: {{car.price}} (please, highlight the infoWindow in map onmouseover)
   </li>
</ul>

Then change the class on the div with ng-class:

var content = '<div id="iw" ng-click=showDetails() ng-class="{'highlight': car.highlight}">{{infoWindowText}} €</div>';

Define the css class highlight to highlight your div

Update

I updated your plunker to change ng-class attribute. Car id must be resolved before ng-class because it is not in the directive scope:

ng-class="{highlight: ' + cars[i].id + ' == selectedCar}"

If you want update the InfoWindow style, you need to retrieve the InfoWindow from the car when the car selected change. You can add a watch on selectedCar in you directive, get the infoWindow matching then edit the style with JQuery


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...