【问题标题】:AngularJS ng-mouseenter not working in child divAngularJS ng-mouseenter 在子 div 中不起作用
【发布时间】:2015-06-06 21:32:14
【问题描述】:

我一直在使用 AngularJS ng-mouseenter 和 mg-mouseleave,这几乎是我死亡的原因。快速解释:

<div class="characterSum">
    <div class="avatarContainer" ng-mouseenter="showButton = true" ng-mouseout="showButton = false">
        <img ng-src="{{imagePath}}" class="img-thumbnail">
        <div class="addImage" ng-show="showButton && (imagePath == 'images/chars/defaultCharacterAvatar.png')">
            <button class="btn-btn-default">
            Add Character Image
            </button>
        </div> 
    </div>
</div>

CSS 属性:

.avatarContainer {
    max-width: 150px;
    max-height: 150px;
    display:inline-block;
    float:left;
    margin-right:5px;
    position:relative;
}

.characterSum {
    border: 1px;
    min-height:160px;
    position:relative;
}

我相当肯定这与我的 CSS 属性有关。我按照一些说明自动将图像缩放为 150 x 150 大小,这样就可以解释我对这些向导的 CSS 属性。反正我之所以觉得跟它有关系,是因为当我加这个的时候:

<div ng-mouseenter="showButton = true" ng-mouseout"showButton = false">Hi</div>

我将它添加到父类“characterSum”下,当我将鼠标悬停在 Hi 上时,按钮显示。一旦我在子 div 类“avatarContainer”下添加它,它就会停止工作。如果我用这个 div 包装整个 avatarContainer 类,那么:

<div ng-mouseenter="showButton = true" ng-mouseout"showButton = false">
    HI
    <div class="avatarContainer"> ......... </div>
</div>

它只在我靠近 hi 时显示按钮。每当 showButton 发生变化时,我都会在 showButton 上添加 $scope.$watch 到 console.log('detected') >

有人知道我受到了什么疯狂的诅咒吗?或者如果没有,我愿意使用任何其他方式来实现这一点。 (基本上希望按钮在 img 鼠标悬停时显示)。而且我已经尝试将 ng-mouseover 直接应用于 img 元素,但无济于事。

【问题讨论】:

  • 所以当 imagePath 是那个时,鼠标悬停显示按钮。哪一点是你没想到的?
  • 您好,感谢您创建 plnkr!当我将鼠标悬停在图像上时,按钮根本不显示。此外,所有内容都包含在 container-fluid bootstrap div 中。出于某种原因,plnkr 似乎正在工作......我将尝试在另一个 plnkr 中复制这种情况
  • @PhilipTsang 你能在 plunkr 中复制这个问题吗?
  • 不幸的是,我无法在 plunkr 中复制该问题。很多如果我的代码依赖于很多帖子请求(我认为这是问题)和 plunkr 无法做到的 PHP 代码。我设置了一个可以查询的小型迷你服务器。感谢您的帮助

标签: javascript html css angularjs


【解决方案1】:

你有一个错字,你需要使用ng-mouseleave而不是ng-mouseout

标记

<div class="characterSum">
    <div class="avatarContainer" ng-mouseenter="showButton = true" 
     ng-mouseleave="showButton = false">
        <img ng-src="{{imagePath}}" class="img-thumbnail">
        <div class="addImage" ng-show="showButton && (imagePath == 'images/chars/defaultCharacterAvatar.png')">
            <button class="btn-btn-default">
            Add Character Image
            </button>
        </div> 
    </div>
</div>

【讨论】:

  • 在阅读了 ng-mouseout 和 ng-mouseleave 是相同的之后,我切换到了 ng-mosueout,希望能保存我的脚本。不幸的是,什么也没发生
  • yoj可以创建一个plunkr吗??
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-08-06
  • 1970-01-01
  • 2016-02-06
  • 2023-03-28
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多