【发布时间】:2017-05-06 21:51:53
【问题描述】:
在长按手势时,上下文操作菜单会沿所选文本显示。 但除非我从菜单中选择一个选项,否则不会隐藏。
首先启用上下文操作菜单,我使用了这个:
overflow-scroll = "true" in the ion-content.
在 CSS 类中,我写道:
-webkit-user-select: auto;
但现在我无法隐藏它。它被锁定在我的视野中。即使在我的 Web 视图中触摸任何位置后,它仍然处于启用状态。为了隐藏上下文菜单,我使用了这个:
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
-webkit-touch-callout:none;
但仍然没有成功。此特定问题仅在 android 中。对于 iOS,它运行良好。任何帮助将不胜感激。
离子版本 - 2.1.0
更新
我终于找到了答案。
我使用了以下两种方法。长按选择文本的第一种方法和删除选择的第二种方法。
/*----------- To get selection--------*/
$scope.getSelectionText = function() {
var text = "";
if (window.getSelection) {
text = window.getSelection().toString();
$scope.selectMode = true;
} else if (document.selection && document.selection.type != "Control") {
text = document.selection.createRange().text;
$scope.selectMode = true;
}
return text;
};
/*---------------To remove selection----------*/
$scope.remove = function(){
if (window.getSelection) {
if (window.getSelection().empty) { // Chrome
window.getSelection().empty();
} else if (window.getSelection().removeAllRanges) { // Firefox
window.getSelection().removeAllRanges();
}
} else if (document.selection) { // IE?
document.selection.empty();
}
};
并将 ng-click 添加到您的 div
<div class="selectable" ng-click="remove()">
<ng-include src="activeTab.url"></ng-include>
</div>
【问题讨论】:
标签: android angularjs ionic-framework