ionic html 复制,ionic 应用中的文字不能长按复制、粘贴问题解决

项目临近上线,遇到了奇葩问题,ionic中的文字是无法像普通wap页面一样复制粘贴的。

翻了翻官方文档和中文网站,都没有对这个问题的说明。

后来经过多方查找资料,解决了这个问题。接下来分享给大家。

直接上代码:

html部分

Ionic文字复制问题

ionic 测试copy

幻灯片1测试文字,试试可以复制

css部分

ion-content{

overflow-scroll: true;

}

.scroll-content {

-webkit-user-select: auto !important;

-moz-user-select: auto !important;

-ms-user-select: auto !important;

user-select: auto !important;

}

.selectable {

-webkit-user-select: auto;//控制网页内容选择范围

}

js部分

angular.module('ionicApp', ['ionic'])

.controller('MyCtrl', function($scope) {

stop_browser_behavior: false

self.touchStart = function(e) {

self.startCoordinates = getPointerCoordinates(e);

if ( ionic.tap.ignoreScrollStart(e) ) {

return;

}

if( ionic.tap.containsOrIsTextInput(e.target) ) {

// do not start if the target is a text input

// if there is a touchmove on this input, then we can start the scroll

self.__hasStarted = false;

return;

}

self.__isSelectable = true;

self.__enableScrollY = true;

self.__hasStarted = true;

self.doTouchStart(e.touches, e.timeStamp);

// e.preventDefault();

};

});

通过代码我们可以看到,首先在html中,添加overflow-scroll='true',然后在我们想要复制文字的容器上,添加自定义类,代码中我们添加的是'.selectable' ,在这个类上设置我们的css样式。

这里需要注意的是,这个自定义类,不能加在ionic的特定标签上。如下:

这样写,是无效的,我们必须这样写:

幻灯片1测试文字,试试可以复制

表示我就是因为这个没写对,调试了半天出不来效果。。。

最后一步就是在页面对应的controller里面拷贝如上js代码。

在这里附上实例demo,可以预览效果:


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部