悬停更改图像会更改整行图像

时间:2018-08-01 06:21:25

标签: javascript css html-table

我正在显示<td>单元内的图像。悬停时,我正在更改图像。但是看来我做错了。

<td class="col-md-1">

  <div class="request-container" popover-popup-delay=200 popover-enable="match.noOfRequests !== 0" ng-click="src.searchSummary($event, match, $index)" uib-popover-template="'./ui-search-result-summary.html'" popover-class="search-result-popover" popover-placement="left-top"
    popover-trigger="'outsideClick'" ng-class="{highlighted: match.isRequestMatch}" id="popOverElement" ng-mouseover="src.requestHover = true" ng-mouseleave="src.requestHover = false" ng-class="{'active': src.requestHover}">

    <span class="result-request"> {{match.noOfRequests}} </span>
    <img class="request-img" ng-src="{{(src.requestHover ) && 'img/sprites/Study.svg#Requests-White-View' || 'img/sprites/Study.svg#Requests-Brown-View'}}">
  </div>
</td>

CSS:

.request-container {
  width: 100%;
  height: 90%;
  padding-top: 10px;
  cursor: pointer;
  &.active {
    background-color: $color-brown;
    color: white;
    text-decoration-color: white !important;
  }
  &:hover {
    background-color: $color-brown;
    color: white;
    text-decoration-color: white !important;
  }
}

requestHover是一个标志,我在悬停时将其设置为truefalse。有人可以帮我吗?

2 个答案:

答案 0 :(得分:1)

问题与您正在使用的CSS代码段有关。我正在修改CSS,请参阅下面的内容。更改图像悬停以使其正常工作。

.request-container {
  width: 100%;
  height: 90%;
  padding-top: 10px;
  cursor: pointer;
  &.active {
    background-color: $color-brown;
    color: white;
    text-decoration-color: white !important;
  }
  img {
    &:hover {
    background-color: $color-brown;
    color: white;
    text-decoration-color: white !important;
  }
}
}

答案 1 :(得分:0)

我通过鼠标悬停的函数调用解决了我的问题,该函数刚刚在ng-mouse-hover上传递了索引值,并在图像上添加了检查以解决我的问题。

 <td class="col-md-1" style= "padding:10 px">
     <div class="request-container" popover-popup-delay=200 popover-enable="match.noOfRequests !== 0" ng-click="src.searchSummary($event, match, $index)"
      uib-popover-template="'./ui-search-result-summary.html'" popover-class="search-result-popover" popover-placement="left-top" popover-trigger="'outsideClick'" 
      ng-class= "{highlighted: match.isRequestMatch}" id="popOverElement"
      ng-mouseover = " src.requestOnHover($index)" ng-mouseleave = "src.requestHover = false" ng-class= "{'active': src.requestHover}">
      <span class="result-request" > {{match.noOfRequests}} </span>
        <img class= "request-img" ng-src="{{(src.requestHover && src.hoverIndex == $index ) && 'img/sprites/Study.svg#Requests-White-View' || 'img/sprites/Study.svg#Requests-Brown-View'}}">
     </div>
 </td>

我的控制器-

vm.requestOnHover = function(index) {
  vm.hoverIndex = index;
  vm.requestHover = true;
};