Sam*_*ain 6 mouseover onmouseover angularjs angularjs-directive
我是AngularJS的新手,如何mouseover使用AngularJS 显示弹出窗口.如果我在鼠标悬停时调整div的大小,它会改变整个结构,如何在不打扰邻居元素的情况下显示弹出div.
标记
<div ng-repeat="x in images | filter:test" style="float:left; width:30%" ng-mouseover="count=1" ng-mouseleave="count=0" >
<img ng-src="{{x.path}}"
style="width: 100px; height:100px"><div> {{x.company}}</div>
<div style="background-color:#E6E6FA;text-align: center;"ng-show="count">
price:{{x.price}}</br>
size:{{x.size}}</br>
</div>
</img>
<div/>
Run Code Online (Sandbox Code Playgroud)
我在标记中添加了额外的东西,如公司,尺寸mouseover.帮助我弹出一个图像mouseover.提前致谢
你必须做两件事.首先,您必须将弹出元素置于绝对位置,以便在弹出时不会干扰其他元素的流动.像这样的东西(z-index使它超越其他元素):
.popover {
position: absolute;
z-index: 100;
}
Run Code Online (Sandbox Code Playgroud)
在你的html标记中,你可以使用ng-mouseover指令.
<div ng-mouseover="showPopover()" ng-mouseleave="hidePopover()">
more info
</div>
<div class="popover" ng-show="popoverIsVisible">Popover Content</div>
Run Code Online (Sandbox Code Playgroud)
您的角度控制器可能看起来像这样
$scope.showPopover = function() {
$scope.popoverIsVisible = true;
};
$scope.hidePopover = function () {
$scope.popoverIsVisible = false;
};
Run Code Online (Sandbox Code Playgroud)
如果你有多个,你最好把所有这些东西都放到一个指令中