AngularJS: show hide elements based on mouse events

独自空忆成欢 提交于 2019-12-11 03:38:43

问题


Here is an example - http://plnkr.co/edit/iwvjJcUurUW2AvkDArfz?p=preview

I would like the delete button to show up only when mouse hovers on the row and perform some function delete(name), by passing the name

How can I achieve this?

P.S I am new to Angular world


回答1:


This can be quickly solved with CSS, no need to bring JS or Angular. Just using basic CSS would be in my opinion better solution. Add the following to your stylesheet:

 <style>
   tr i.icon-minus-sign { display: none; }
   tr:hover i.icon-minus-sign { display: block; };
 </style>



回答2:


Andres answer is great, but I think many people who stumble upon this page will appreciate this variation:

 <style>
   tr i.icon-minus-sign { visibility: hidden; }
   tr:hover i.icon-minus-sign { visibility: visible; };
 </style>

This is better in many cases, because when using visibility:hidden, the element is still there but just invisible, so it takes up space even when it's not shown. That's why the table and cells will not change size when hovering over the row.



来源:https://stackoverflow.com/questions/16535383/angularjs-show-hide-elements-based-on-mouse-events

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!