javascript - 使用 AngularJS UI 使工具提示位置相对于窗口大小

标签 javascript jquery angularjs twitter-bootstrap

我正在尝试根据屏幕分辨率更改工具提示的位置(基于 AngularJS Bootstrap UI),基本上是在移动设备上显示第一个,在其余位置上显示第二个(最小宽度 ≥ 768px) :

tooltip-placement="top"


tooltip-placement="left"

我找到了一个使用 jQuery 的解决方案(下一段代码),但我不知道如何在 Angular 中实现它。

$(window).on('resize', function() {
  var pos = ($(window).width() < 768) ? 'left' : 'top';
  $("#myDiv").tooltip({'placement': pos});
}).trigger('resize');

有什么提示吗?

最佳答案

您可以在范围内定义一个函数来确定工具提示的位置。例如:

$scope.getTooltipPlacement = function () {
    return ($(window).width() < 768) ? 'left' : 'top';
};

然后在您想要工具提示的元素上,您可以在 tooltip-placement 属性中调用此函数:

<a href="#" tooltip="My awesome tooltip" tooltip-placement="{{getTooltipPlacement()}}">Link</a>

关于javascript - 使用 AngularJS UI 使工具提示位置相对于窗口大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23024570/

相关文章:

javascript - AngularJS 小测试应用程序渲染速度极慢

javascript - AngularJs 从工厂调用 Controller 函数

AngularJS 使用 ng-switch 没有包装 div

javascript - 如果在 yup Schema 验证中任何字段非空,则不需要任何字段或需要所有字段

php - 如何在codeigniter中给出完整的 Controller 路径

javascript - 页面加载时触发 jQuery 函数

jquery - jQuery 添加的替代文字会影响 SEO 吗?

javascript - 在转到其他页面之前检查复选框是否已选中

javascript - 如何滚动到一个元素?

javascript - 如果无法修改 JSONP 中的 header 。 Chrome 中的 Twitter 扩展程序如何工作?