1. 程式人生 > >在cocos creator裏添加二維碼

在cocos creator裏添加二維碼

loading element cnblogs htm prevent touch func tee brush

在cocos creator裏添加二維碼,剛開始用webview做,在微信裏,安卓可以識別,但是IOS識別不了。後來用了地址跳轉的方法實現了,但是每次返回的時候,都要loading一次,這樣用戶體驗很不好,最近找到一種方法可以使得二維碼顯示在cocos creator裏面,並且安卓和IOS都可以識別。 就是在index.html裏先寫個div,然後在button事件裏添加二維碼的img:

index.html

<div id="contain" style="position:absolute;top:0px;width:100%;height:100%;"></div>

button事件

var imgNode = document.createElement(‘img‘);
var contain = window.document.getElementById("contain");

這樣完成之後,有個不足的地方就是,頁面可以下拉,為了防止下拉,還順便要寫個防止下拉的方法:

<div class="bottom"></div>

document.querySelector(‘body‘).addEventListener(‘touchmove‘, function(e){
    if (!document.querySelector(‘.bottom‘).contains(e.target)) {
        e.preventDefault();
    }
})
    

在cocos creator裏添加二維碼