简体   繁体   English

在悬停时显示 div,仅当前显示(一次一个,而不是一次全部显示)

[英]Show div on hover, of current only (one at a time, not all at once)

I am currently using the below:我目前正在使用以下内容:

angular JS:角JS:

$scope.showPopover = function() {
  $scope.popoverIsVisible = true; 
};

$scope.hidePopover = function () {
  $scope.popoverIsVisible = false;
};

Mark-Up:标记:

<span class="margin-top-10 display-block">{{doc.pcpText}}
  <span class="bCert" ng-mouseover="showPopover()"
        ng-mouseleave="hidePopover()">Board Certified: 
    <img src="https://www.verycool.website.com/core/images/questionmark.png"
         class="question_mark"> 
    <span class="yes">Yes</span>
  </span>
  <span class="VerC">Verify Certification
  </span>
</span>
<span class="boxShow" ng-show="popoverIsVisible">
  Which board(s) certifies the provider. This information is blah blah blah 
  12 months.
</span>
  • The problem with it;它的问题; is it shows the tool tips/hovers all at once when you hover over it.当您将鼠标悬停在它上面时,它是否会同时显示工具提示/悬停。 I only want to instantiate this over the current item being hovered, so one at a time, instead of all at once, any suggestions?我只想在当前悬停的项目上实例化它,所以一次一个,而不是一次,有什么建议吗? My mark-up above is dynamically included down the page;我上面的标记是动态包含在页面下方的; so I don't want to hover over the first, and have all the below 'tooltip boxes' show, as it is currently.所以我不想将鼠标悬停在第一个上,并像当前一样显示下面的所有“工具提示框”。 I just want to show the hover of the current one.我只想显示当前悬停。

Define a variable that value set to false if tooltip was displayed once.如果工具提示显示一次,则定义一个值设置为 false 的变量。 In example - tooltipIsNotDisplayed在示例中 - tooltipIsNotDisplayed

 angular.module('app', []) .directive('example', example) .directive('popover', popover); function example() { return { templateUrl: 'example.directive.html' } } function popover() { return { restrict: 'A', link: function popover($scope, $elem, $attrs) { $scope.popoverMessage = $attrs.popoverMessage; $elem.addClass('popover'); $elem.append('<div class="popover-message">' + $scope.popoverMessage + '</div>'); } } } angular.bootstrap( document.getElementById('root'), ['app'] );
 body { font-family: sans-serif; } .popover .popover-message { display: none; } .popover:hover .popover-message { display: block; }
 <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.5/angular.min.js"></script> <div id="root"> <script type="text/ng-template" id="example.directive.html"> <span popover popover-message="popover message"> text </span> <span popover popover-message="other popover message"> other text </span> </script> <example></example> </div>

Make the popoverIsVisible variable a hash:使popoverIsVisible变量成为散列:

$scope.popoverIsVisible = {};

$scope.showPopover = function(id) {
  $scope.popoverIsVisible[id] = true; 
};

$scope.hidePopover = function (id) {
  $scope.popoverIsVisible[id] = false;
};

In the template use it:在模板中使用它:

 <span class="bCert" ng-mouseover="showPopover('info1')"
       ng-mouseleave="hidePopover('info1)">Board Certified: 
    <img src="https://www.verycool.website.com/core/images/questionmark.png"
         class="question_mark"> 
    <span class="yes">Yes</span>
 </span>
 <span class="boxShow" ng-show="popoverIsVisible.info1">
  Which board(s) certifies the provider. This information is blah blah blah 12 months.
</span>

 <span class="bCert" ng-mouseover="showPopover('otherInfo')"
       ng-mouseleave="hidePopover('otherInfo')">Other content
 </span>
 <span class="boxShow" ng-show="popoverIsVisible.otherInfo">
  Other  blah blah blah 12 months.
</span>
$scope.showPopover = function() {
  this.popoverIsVisible = true; 
};

$scope.hidePopover = function () {
  this.popoverIsVisible = false;
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM