[英]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>
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.