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,可以预览效果:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值