HBuilderX

HBuilderX

极客开发工具
uni-app

uni-app

开发一次,多端覆盖
uniCloud

uniCloud

云开发平台
HTML5+

HTML5+

增强HTML5的功能体验
MUI

MUI

上万Star的前端框架

【分享】触摸返回值 相关变量touches,targetTouches和changedTouches的区别

事件

touches: 当前屏幕上所有触摸点的列表;

targetTouches: 当前对象上所有触摸点的列表;

changedTouches: 涉及当前事件的触摸点的列表
通过一个例子来区分一下触摸事件中的这三个属性:
用一个手指接触屏幕,触发事件,此时这三个属性有相同的值。
用第二个手指接触屏幕,此时,touches有两个元素,每个手指触摸点为一个值。当两个手指触摸相同元素时,targetTouches和touches的值相同,否则targetTouches 只有一个值。changedTouches此时只有一个值,为第二个手指的触摸点。
用两个手指同时接触屏幕,此时changedTouches有两个值,每一个手指的触摸点都有一个值
手指滑动时,三个值都会发生变化
一个手指离开屏幕,touches和targetTouches中对应的元素会同时移除,而changedTouches仍然会存在元素。
手指都离开屏幕之后,touches和targetTouches中将不会再有值,changedTouches还会有一个值,此值为最后一个离开屏幕的手指的接触点。

继续阅读 »

touches: 当前屏幕上所有触摸点的列表;

targetTouches: 当前对象上所有触摸点的列表;

changedTouches: 涉及当前事件的触摸点的列表
通过一个例子来区分一下触摸事件中的这三个属性:
用一个手指接触屏幕,触发事件,此时这三个属性有相同的值。
用第二个手指接触屏幕,此时,touches有两个元素,每个手指触摸点为一个值。当两个手指触摸相同元素时,targetTouches和touches的值相同,否则targetTouches 只有一个值。changedTouches此时只有一个值,为第二个手指的触摸点。
用两个手指同时接触屏幕,此时changedTouches有两个值,每一个手指的触摸点都有一个值
手指滑动时,三个值都会发生变化
一个手指离开屏幕,touches和targetTouches中对应的元素会同时移除,而changedTouches仍然会存在元素。
手指都离开屏幕之后,touches和targetTouches中将不会再有值,changedTouches还会有一个值,此值为最后一个离开屏幕的手指的接触点。

收起阅读 »

原生 hbuilder 插件开发,各种js 调用 回调

插件开发

原生 hbuilder 插件开发,各种js 调用 回调

如有需求可以联系511308538

原生 hbuilder 插件开发,各种js 调用 回调

如有需求可以联系511308538

chrom调试器打开空白,不能调试模拟器手机软件

改一下hosts试一试

74.125.25.141 chrome-devtools-frontend.appspot.com

改一下hosts试一试

74.125.25.141 chrome-devtools-frontend.appspot.com

上传图片功能(包含,可多个容器,可修改图片,重新上传等)

/**  
 * 上传图片插件  
 * varstion 1.0.0  
 * by Allen-Fei  
 * tipefi@126.com  
 * 参数列表:  
 * el——图片容器(建议用class,可用于多个)  
 * closeId——图片容器里的关闭按钮  
 * bg——用于判断容器内是否存在图片  
 * submitId——提交按钮ID  
 * size——上传图片的文件大小  
 * url——上传图片的服务器API  
 * addData——上传图片时需要附带的其他参数(比如token)  
 * success——上传成功的回调  
 * error——上传失败的回调  
 * 流程:  
 * 先选择图片到图片容器(添加的图片会填充为容器背景),再点提交按钮提交到服务器  
 * 用法:  
 * var upLoader = new UpLoader(); // 先new出来  
 * upLoader.init({}) // 再调用init初始化,传入相应参数  
 * 基于zepto或jq、mui------仅限手机端  
 */  
!function(window, undefined) {  
    var layer = '<div id="selectLayer" class="mui-popover mui-popover-bottom mui-popover-action ">'  
    layer += '<ul class="mui-table-view" id="imgLayer">'  
    layer += '<li class="mui-table-view-cell">'  
    layer += '<span>拍照</span>'  
    layer += '</li>'  
    layer += '<li class="mui-table-view-cell">'  
    layer += '<span>从相册选择</span>'  
    layer += '</li>'  
    layer += '</ul>'  
    layer += '<ul class="mui-table-view">'  
    layer += '<li class="mui-table-view-cell">'  
    layer += '<a href="#selectLayer"><b>取消</b></a>'  
    layer += '</li>'  
    layer += '</ul>'  
    layer += '</div>'  
    var $this = null,  
        tapInt = 0;  
    var UpLoader = window.UpLoader = function() {  
        this.imgUrl = []; //存放待上传的图片  
        this.zoomLevel = 0; //放大状态  
        this.zoomLeft = 0; //图片移动的暂存数据(左边位置)  
        this.zoomTop = 0; //图片移动的暂存数据(顶部位置)  
        this.o = {}; //存放传过来的参数  
        this.index = 0; //当前操作的索引值  
        this.m = 2; //放大倍数  
        this.$imgBox = null; //浏览图片的外框Dom  
    }  

    UpLoader.prototype.init = function(option) {  
        var that = this;  
        that.o = option;  
        //点击图标上传事件  
        $("body").on("tap", that.o.el, function() {  
            $this = $(this);  
            that.index = $(that.o.el).index($this);  
            if($this.hasClass(that.o.bg)) {  
                that.browseImg();  
                return false;  
            } else {  
                if($("#selectLayer").size() <= 0) {  
                    $("body").append(layer);  

                }  
            }  
            mui('#selectLayer').popover('toggle');  
        })  
        //选择方式事件  
        $("body").on("tap", "#imgLayer li", function() {  
            var i = $(this).parent().children().index(this)  
            switch(i) {  
                case 0:  
                    that.getImages();  
                    break;  
                case 1:  
                    that.getPhoto();  
                    break;  
                default:  
                    break;  
            }  
            mui('#selectLayer').popover('hide');  
        })  
        //移除图片事件  
        $("body").on("tap", that.o.closeId, function() {  
            that.index = $(that.o.closeId).index(this);  
            that.removeImg($(this));  
        })  
        //单击退出浏览事件  
        $("body").on("tap", "#imgBox", function(event) {  
            var _this = $(this);  
            tapInt = 0;  
            if(!tapInt) {  
                setTimeout(function() {  
                    if(tapInt == 0) {  
                        _this.remove();  
                        tapInt = 0  
                    }  
                }, 500)  
            }  
        })  
        //双击放大事件  
        $("body").on("doubletap", "#imgBox", function() {  
            var _this = $(this);  
            if(that.zoomLevel) {  
                that.zoomOut()  
            } else {  
                that.zoomIn()  
            }  
            tapInt = 2;  
        })  

        //拖动中事件  
        $("body").on("drag", "#imgBox img", function(e) {  
            if(that.zoomLeft == 0) return false;  
            $("#imgBox").children("img").css({  
                "margin-left": that.zoomLeft + event.detail.deltaX + "px",  
                "margin-top": that.zoomTop + event.detail.deltaY + "px"  
            })  
        })  
        //拖动结束  
        $("body").on("dragend", "#imgBox img", function(e) {  
            if(that.zoomLeft == 0) return false;  
            that.zoomLeft += event.detail.deltaX; //要在拖动结束后保存位置  
            that.zoomTop += event.detail.deltaY;  
        })  
        //提交事件  
        $("body").on("tap", that.o.submitId, function() {  
            that.imgSubmit();  
        })  
    }  

    //拍照获取图片  
    UpLoader.prototype.getImages = function() {  
        var that = this;  
        var cmr = plus.camera.getCamera();  
        cmr.captureImage(function(p) {  
                plus.io.resolveLocalFileSystemURL(p, function(entry) {  
                    //转化本地绝对路径  
                    that.displayImg(entry.fullPath);  
                });  
            }, function(error) {  
                console.log("---" + "捕获图像失败: " + error.message);  
            }, {} //建议使用系统匹配路径  
        );  
    }  

    //从相册获取图片  
    UpLoader.prototype.getPhoto = function() {  
        var that = this;  
        plus.gallery.pick(function(path) {  
            that.displayImg(path);  
        }, function(error) {  
            console.log("---" + "捕获图像失败: " + error.message);  
        })  
    }  

    //填充图片  
    UpLoader.prototype.displayImg = function(p) {  
        var that = this;  
        that.rotateImg(p)  
    }  

    //处理旋转,iOS上坚向照片填充时会自动逆时钟旋转90,故用压缩方法旋转0度  
    UpLoader.prototype.rotateImg = function(p) {  
        var that = this;  
        if(p.indexOf('http') < 0) {  
            ~p.indexOf("file:") ? p : p = "file:///" + p;  
            plus.zip.compressImage({  
                src: p,  
                dst: p,  
                overwrite: true,  
                rotate: 0 // 不管有没有被旋转,统一旋转0度  
            }, function() {  
                that.imgUrl[that.index] = p;  
                $this.addClass(that.o.bg).css({  
                    "background-image": "url(" + p + ")"  
                })  
            }, function(error) {  
                mui.toast("图片旋转时发生错误!");  
            });  
        } else {  
            var index = that.imgUrl.indexOf(p);  
            $(that.o.el).eq(index).addClass(that.o.bg).css({  
                "background-image": "url(" + p + ")"  
            })  
        }  

    }  

    //移除图片  
    UpLoader.prototype.removeImg = function(_this) {  
        var that = this;  
        that.imgUrl[that.index] = "";  
        _this.next(that.o.el).removeClass(that.o.bg).removeAttr("style");  
    }  

    //放大追加图片浏览DOM  
    UpLoader.prototype.browseImg = function(index) {  
        $("body").append('<div id="imgBox"></div>');  
        var that = this;  
        that.$imgBox = $("#imgBox");  
        that.$imgBox.css({  
            "position": "absolute",  
            "top": 0,  
            "left": 0,  
            "width": "100%",  
            "height": "100%",  
            "background": "#000",  
            "z-index": 9999,  
            "overflow": "hidden;"  
        }).append('<img>').children("img").attr("src", that.imgUrl[that.index]).css("width", "100%");  
        that.zoomLeft = 0;  
        that.zoomTop = (window.screen.height - 20 - that.$imgBox.children("img").height()) / 2;  
        that.upImgPostion();  
    }  

    //更新图片显示位置  
    UpLoader.prototype.upImgPostion = function(type) {  
        var that = this;  
        var imgH = that.$imgBox.children("img").height();  
        var imgW = that.$imgBox.children("img").width();  
        var winH = window.screen.height - 20;  
        var winW = window.screen.width;  
        if(imgH < winH) {  
            that.$imgBox.children("img").css({  
                "margin-top": (winH - imgH) / 2 + "px"  
            })  
        }  
        if(type == "in") {  
            that.$imgBox.children("img").css({  
                "margin-left": (that.zoomLeft - imgW / that.m / that.m) + "px",  
                "margin-top": (that.zoomTop - imgH / that.m / that.m) + "px"  
            })  
            that.zoomLeft = that.zoomLeft - imgW / that.m / that.m;  
            that.zoomTop = that.zoomTop - imgH / that.m / that.m;  
        }  
        if(type == "out") {  
            that.$imgBox.children("img").css({  
                "margin-left": "0px",  
                "margin-top": (winH - imgH) / 2 + "px"  
            })  
            that.zoomLeft = 0;  
            that.zoomTop = (winH - imgH) / 2;  
        }  
    }  

    //图片放大   
    UpLoader.prototype.zoomIn = function() {  
        var that = this;  
        that.$imgBox.children("img").width(that.$imgBox.children("img").width() * that.m); //不要设置高度,因为高度是随宽度变化的  
        that.zoomLevel = 1;  
        that.upImgPostion("in");  
    }  

    //图片缩小  
    UpLoader.prototype.zoomOut = function() {  
        var that = this;  
        that.$imgBox.children("img").width(that.$imgBox.children("img").width() / that.m);  
        that.zoomLevel = 0;  
        that.upImgPostion("out");  
    }  

    //添加数据  
    UpLoader.prototype.addData = function(obj) {  
        this.data = obj;  
    }  

    //添加图片  
    UpLoader.prototype.addImg = function(arr) {  
        if(arr instanceof Array) {  
            for(var i = 0; i < arr.length; i++) {  
                this.imgUrl.push(arr[i]);  
                this.displayImg(arr[i])  
            }  
        } else {  
            this.displayImg(arr)  
        }  
    }  

    //提交图片  
    UpLoader.prototype.imgSubmit = function() {  
        var that = this;  
        that.data = that.o.addData instanceof Function ? that.o.addData() : '';  
        if(that.data === false) return false;  
        var task = plus.uploader.createUpload(that.o.url, {  
            method: "POST",  
            blocksize: that.o.size,  
            priority: 100  
        }, function(t, status) {  
            // 上传完成  
            if(status == 200) {  
                that.o.success(t, status);  
            } else {  
                that.o.error(t, status);  
            }  
        })  
        for(var i = 0; i < that.imgUrl.length; i++) {  
            if(that.imgUrl[i]) { //遍历图片数组,去除空的值  
                task.addFile(that.imgUrl[i], {  
                    key: "img" + i  
                });  
            }  
        }  

        if(JSON.stringify(that.data) != "{}" || !JSON.stringify(that.data)) {  
            for(var key in that.data) {  
                task.addData(key, that.data[key]);  
            }  

        }  

        task.start();  
    }  

}(window)
继续阅读 »
/**  
 * 上传图片插件  
 * varstion 1.0.0  
 * by Allen-Fei  
 * tipefi@126.com  
 * 参数列表:  
 * el——图片容器(建议用class,可用于多个)  
 * closeId——图片容器里的关闭按钮  
 * bg——用于判断容器内是否存在图片  
 * submitId——提交按钮ID  
 * size——上传图片的文件大小  
 * url——上传图片的服务器API  
 * addData——上传图片时需要附带的其他参数(比如token)  
 * success——上传成功的回调  
 * error——上传失败的回调  
 * 流程:  
 * 先选择图片到图片容器(添加的图片会填充为容器背景),再点提交按钮提交到服务器  
 * 用法:  
 * var upLoader = new UpLoader(); // 先new出来  
 * upLoader.init({}) // 再调用init初始化,传入相应参数  
 * 基于zepto或jq、mui------仅限手机端  
 */  
!function(window, undefined) {  
    var layer = '<div id="selectLayer" class="mui-popover mui-popover-bottom mui-popover-action ">'  
    layer += '<ul class="mui-table-view" id="imgLayer">'  
    layer += '<li class="mui-table-view-cell">'  
    layer += '<span>拍照</span>'  
    layer += '</li>'  
    layer += '<li class="mui-table-view-cell">'  
    layer += '<span>从相册选择</span>'  
    layer += '</li>'  
    layer += '</ul>'  
    layer += '<ul class="mui-table-view">'  
    layer += '<li class="mui-table-view-cell">'  
    layer += '<a href="#selectLayer"><b>取消</b></a>'  
    layer += '</li>'  
    layer += '</ul>'  
    layer += '</div>'  
    var $this = null,  
        tapInt = 0;  
    var UpLoader = window.UpLoader = function() {  
        this.imgUrl = []; //存放待上传的图片  
        this.zoomLevel = 0; //放大状态  
        this.zoomLeft = 0; //图片移动的暂存数据(左边位置)  
        this.zoomTop = 0; //图片移动的暂存数据(顶部位置)  
        this.o = {}; //存放传过来的参数  
        this.index = 0; //当前操作的索引值  
        this.m = 2; //放大倍数  
        this.$imgBox = null; //浏览图片的外框Dom  
    }  

    UpLoader.prototype.init = function(option) {  
        var that = this;  
        that.o = option;  
        //点击图标上传事件  
        $("body").on("tap", that.o.el, function() {  
            $this = $(this);  
            that.index = $(that.o.el).index($this);  
            if($this.hasClass(that.o.bg)) {  
                that.browseImg();  
                return false;  
            } else {  
                if($("#selectLayer").size() <= 0) {  
                    $("body").append(layer);  

                }  
            }  
            mui('#selectLayer').popover('toggle');  
        })  
        //选择方式事件  
        $("body").on("tap", "#imgLayer li", function() {  
            var i = $(this).parent().children().index(this)  
            switch(i) {  
                case 0:  
                    that.getImages();  
                    break;  
                case 1:  
                    that.getPhoto();  
                    break;  
                default:  
                    break;  
            }  
            mui('#selectLayer').popover('hide');  
        })  
        //移除图片事件  
        $("body").on("tap", that.o.closeId, function() {  
            that.index = $(that.o.closeId).index(this);  
            that.removeImg($(this));  
        })  
        //单击退出浏览事件  
        $("body").on("tap", "#imgBox", function(event) {  
            var _this = $(this);  
            tapInt = 0;  
            if(!tapInt) {  
                setTimeout(function() {  
                    if(tapInt == 0) {  
                        _this.remove();  
                        tapInt = 0  
                    }  
                }, 500)  
            }  
        })  
        //双击放大事件  
        $("body").on("doubletap", "#imgBox", function() {  
            var _this = $(this);  
            if(that.zoomLevel) {  
                that.zoomOut()  
            } else {  
                that.zoomIn()  
            }  
            tapInt = 2;  
        })  

        //拖动中事件  
        $("body").on("drag", "#imgBox img", function(e) {  
            if(that.zoomLeft == 0) return false;  
            $("#imgBox").children("img").css({  
                "margin-left": that.zoomLeft + event.detail.deltaX + "px",  
                "margin-top": that.zoomTop + event.detail.deltaY + "px"  
            })  
        })  
        //拖动结束  
        $("body").on("dragend", "#imgBox img", function(e) {  
            if(that.zoomLeft == 0) return false;  
            that.zoomLeft += event.detail.deltaX; //要在拖动结束后保存位置  
            that.zoomTop += event.detail.deltaY;  
        })  
        //提交事件  
        $("body").on("tap", that.o.submitId, function() {  
            that.imgSubmit();  
        })  
    }  

    //拍照获取图片  
    UpLoader.prototype.getImages = function() {  
        var that = this;  
        var cmr = plus.camera.getCamera();  
        cmr.captureImage(function(p) {  
                plus.io.resolveLocalFileSystemURL(p, function(entry) {  
                    //转化本地绝对路径  
                    that.displayImg(entry.fullPath);  
                });  
            }, function(error) {  
                console.log("---" + "捕获图像失败: " + error.message);  
            }, {} //建议使用系统匹配路径  
        );  
    }  

    //从相册获取图片  
    UpLoader.prototype.getPhoto = function() {  
        var that = this;  
        plus.gallery.pick(function(path) {  
            that.displayImg(path);  
        }, function(error) {  
            console.log("---" + "捕获图像失败: " + error.message);  
        })  
    }  

    //填充图片  
    UpLoader.prototype.displayImg = function(p) {  
        var that = this;  
        that.rotateImg(p)  
    }  

    //处理旋转,iOS上坚向照片填充时会自动逆时钟旋转90,故用压缩方法旋转0度  
    UpLoader.prototype.rotateImg = function(p) {  
        var that = this;  
        if(p.indexOf('http') < 0) {  
            ~p.indexOf("file:") ? p : p = "file:///" + p;  
            plus.zip.compressImage({  
                src: p,  
                dst: p,  
                overwrite: true,  
                rotate: 0 // 不管有没有被旋转,统一旋转0度  
            }, function() {  
                that.imgUrl[that.index] = p;  
                $this.addClass(that.o.bg).css({  
                    "background-image": "url(" + p + ")"  
                })  
            }, function(error) {  
                mui.toast("图片旋转时发生错误!");  
            });  
        } else {  
            var index = that.imgUrl.indexOf(p);  
            $(that.o.el).eq(index).addClass(that.o.bg).css({  
                "background-image": "url(" + p + ")"  
            })  
        }  

    }  

    //移除图片  
    UpLoader.prototype.removeImg = function(_this) {  
        var that = this;  
        that.imgUrl[that.index] = "";  
        _this.next(that.o.el).removeClass(that.o.bg).removeAttr("style");  
    }  

    //放大追加图片浏览DOM  
    UpLoader.prototype.browseImg = function(index) {  
        $("body").append('<div id="imgBox"></div>');  
        var that = this;  
        that.$imgBox = $("#imgBox");  
        that.$imgBox.css({  
            "position": "absolute",  
            "top": 0,  
            "left": 0,  
            "width": "100%",  
            "height": "100%",  
            "background": "#000",  
            "z-index": 9999,  
            "overflow": "hidden;"  
        }).append('<img>').children("img").attr("src", that.imgUrl[that.index]).css("width", "100%");  
        that.zoomLeft = 0;  
        that.zoomTop = (window.screen.height - 20 - that.$imgBox.children("img").height()) / 2;  
        that.upImgPostion();  
    }  

    //更新图片显示位置  
    UpLoader.prototype.upImgPostion = function(type) {  
        var that = this;  
        var imgH = that.$imgBox.children("img").height();  
        var imgW = that.$imgBox.children("img").width();  
        var winH = window.screen.height - 20;  
        var winW = window.screen.width;  
        if(imgH < winH) {  
            that.$imgBox.children("img").css({  
                "margin-top": (winH - imgH) / 2 + "px"  
            })  
        }  
        if(type == "in") {  
            that.$imgBox.children("img").css({  
                "margin-left": (that.zoomLeft - imgW / that.m / that.m) + "px",  
                "margin-top": (that.zoomTop - imgH / that.m / that.m) + "px"  
            })  
            that.zoomLeft = that.zoomLeft - imgW / that.m / that.m;  
            that.zoomTop = that.zoomTop - imgH / that.m / that.m;  
        }  
        if(type == "out") {  
            that.$imgBox.children("img").css({  
                "margin-left": "0px",  
                "margin-top": (winH - imgH) / 2 + "px"  
            })  
            that.zoomLeft = 0;  
            that.zoomTop = (winH - imgH) / 2;  
        }  
    }  

    //图片放大   
    UpLoader.prototype.zoomIn = function() {  
        var that = this;  
        that.$imgBox.children("img").width(that.$imgBox.children("img").width() * that.m); //不要设置高度,因为高度是随宽度变化的  
        that.zoomLevel = 1;  
        that.upImgPostion("in");  
    }  

    //图片缩小  
    UpLoader.prototype.zoomOut = function() {  
        var that = this;  
        that.$imgBox.children("img").width(that.$imgBox.children("img").width() / that.m);  
        that.zoomLevel = 0;  
        that.upImgPostion("out");  
    }  

    //添加数据  
    UpLoader.prototype.addData = function(obj) {  
        this.data = obj;  
    }  

    //添加图片  
    UpLoader.prototype.addImg = function(arr) {  
        if(arr instanceof Array) {  
            for(var i = 0; i < arr.length; i++) {  
                this.imgUrl.push(arr[i]);  
                this.displayImg(arr[i])  
            }  
        } else {  
            this.displayImg(arr)  
        }  
    }  

    //提交图片  
    UpLoader.prototype.imgSubmit = function() {  
        var that = this;  
        that.data = that.o.addData instanceof Function ? that.o.addData() : '';  
        if(that.data === false) return false;  
        var task = plus.uploader.createUpload(that.o.url, {  
            method: "POST",  
            blocksize: that.o.size,  
            priority: 100  
        }, function(t, status) {  
            // 上传完成  
            if(status == 200) {  
                that.o.success(t, status);  
            } else {  
                that.o.error(t, status);  
            }  
        })  
        for(var i = 0; i < that.imgUrl.length; i++) {  
            if(that.imgUrl[i]) { //遍历图片数组,去除空的值  
                task.addFile(that.imgUrl[i], {  
                    key: "img" + i  
                });  
            }  
        }  

        if(JSON.stringify(that.data) != "{}" || !JSON.stringify(that.data)) {  
            for(var key in that.data) {  
                task.addData(key, that.data[key]);  
            }  

        }  

        task.start();  
    }  

}(window)
收起阅读 »

【分享】获取图片地址插件(新增返回base64)

图片
/**  
 * 获取图片地址  
 * varstion 1.0.2  
 * by Allen-Fei  
 * tipefi@126.com  
 * 参数列表:  
 * success(picUrl, base64)——图片地址获取成功的回调,返回图片地址及base64  
 * 基于zepto或jq、mui------仅限手机端  
 */  
(function(window, undefind) {  
    var layer = '<div id="selectLayer" class="mui-popover mui-popover-bottom mui-popover-action ">'  
    layer += '<ul class="mui-table-view" id="imgLayer">'  
    layer += '<li class="mui-table-view-cell">'  
    layer += '<span>拍照</span>'  
    layer += '</li>'  
    layer += '<li class="mui-table-view-cell">'  
    layer += '<span>从相册选择</span>'  
    layer += '</li>'  
    layer += '</ul>'  
    layer += '<ul class="mui-table-view">'  
    layer += '<li class="mui-table-view-cell">'  
    layer += '<a href="#selectLayer" id="cancelos"><b>取消</b></a>'  
    layer += '</li>'  
    layer += '</ul>'  
    layer += '</div>'  
    $("body").append(layer);  
    //选择方式事件  
    $("body").on("tap", "#imgLayer li", function() {  
        var i = $(this).parent().children().index(this)  
        if(i == 0) {  
            getImgURL.getImages();  
        }else{  
            getImgURL.getPhoto();  
        }  
        mui('#selectLayer').popover('hide');  
    })  

    $('body').on('tap', '#cancelos', function(){  
        evalID('my-proname.html',['closeDis']);  
    })  

    var getImgURL = window.getImgURL = {  
        init: function(option){ // 初始化方法  
            var that = this;  
            that.o = option;  
            mui('#selectLayer').popover('toggle');  

        },  
        getImages: function(){ // 拍照方法  
            var that = this;  
            var cmr = plus.camera.getCamera(); // 相机对象  
            cmr.captureImage(function(p) { // 拍照事件  
                    that.rotateImg(p);  
                }, function(error) {  
                    that.o.error(error);  
                    console.log("---" + "捕获图像失败: " + error.message);  
                }, {} //建议使用系统匹配路径  
            );  
        },  
        getPhoto: function(){ // 打开相册方法  
            var that = this;  
            plus.gallery.pick(function(path) { // 从系统相册选择图片  
                that.rotateImg(path);             
            }, function(error) {  
                that.o.error(error);  
                console.log("---" + "捕获图像失败: " + error.message);  
            })  
        },  
        rotateImg: function(p) { // 图片处理方法(包括旋转,因在IOS中会有图片读取时会自动旋转,导致读取后的文件不正确)  
            var that = this;  
            if(p.indexOf('http') < 0) {  
                plus.zip.compressImage({  
                    src: p,  
                    dst: p,  
                    overwrite: true,  
                    rotate: 0 // 不管有没有被旋转,统一旋转0度  
                }, function(e) {  
                    if(mui.os.ios){ // 此处IOS需做路径转换处理,在转换时利用文件对象再去转base64,而安卓则直接可以用路径去加载文件  
                        plus.io.resolveLocalFileSystemURL(e.target, function(entry){  
                            entry.file(function(path){  
                                console.log("P__" + JSON.stringify(path));  
                                that.getBase64(path, e.target);   
                            })  
                        });   
                    } else{  
                        that.getBase64(e.target, e.target);  
                    }  
                }, function(error) {  
                    that.o.error(error);  
                    console.log("图片旋转时发生错误!");  
                });  
            } else {  
                that.o.success(p); // 如遇http地址,则直接返回该地址;  
            }  

        },  
        getBase64: function(path, url){                     // 获取Base64  
            var that = this;  
            var reader = new plus.io.FileReader();          // 构建文件对象  
            reader.readAsDataURL(path);                     // 添加文件(此处安卓可以直接添加文件路径,而IOS则需要文件对象)  
            reader.onloadend = function (event) {           // 文件加载 完成后的事件回调  
                //console.log('event'+JSON.stringify(event));  
                that.o.success(url, event.target.result);   // 执行成功函数,统一把路径及base64传过去  
            };  
        }  

    }  

})(window)
继续阅读 »
/**  
 * 获取图片地址  
 * varstion 1.0.2  
 * by Allen-Fei  
 * tipefi@126.com  
 * 参数列表:  
 * success(picUrl, base64)——图片地址获取成功的回调,返回图片地址及base64  
 * 基于zepto或jq、mui------仅限手机端  
 */  
(function(window, undefind) {  
    var layer = '<div id="selectLayer" class="mui-popover mui-popover-bottom mui-popover-action ">'  
    layer += '<ul class="mui-table-view" id="imgLayer">'  
    layer += '<li class="mui-table-view-cell">'  
    layer += '<span>拍照</span>'  
    layer += '</li>'  
    layer += '<li class="mui-table-view-cell">'  
    layer += '<span>从相册选择</span>'  
    layer += '</li>'  
    layer += '</ul>'  
    layer += '<ul class="mui-table-view">'  
    layer += '<li class="mui-table-view-cell">'  
    layer += '<a href="#selectLayer" id="cancelos"><b>取消</b></a>'  
    layer += '</li>'  
    layer += '</ul>'  
    layer += '</div>'  
    $("body").append(layer);  
    //选择方式事件  
    $("body").on("tap", "#imgLayer li", function() {  
        var i = $(this).parent().children().index(this)  
        if(i == 0) {  
            getImgURL.getImages();  
        }else{  
            getImgURL.getPhoto();  
        }  
        mui('#selectLayer').popover('hide');  
    })  

    $('body').on('tap', '#cancelos', function(){  
        evalID('my-proname.html',['closeDis']);  
    })  

    var getImgURL = window.getImgURL = {  
        init: function(option){ // 初始化方法  
            var that = this;  
            that.o = option;  
            mui('#selectLayer').popover('toggle');  

        },  
        getImages: function(){ // 拍照方法  
            var that = this;  
            var cmr = plus.camera.getCamera(); // 相机对象  
            cmr.captureImage(function(p) { // 拍照事件  
                    that.rotateImg(p);  
                }, function(error) {  
                    that.o.error(error);  
                    console.log("---" + "捕获图像失败: " + error.message);  
                }, {} //建议使用系统匹配路径  
            );  
        },  
        getPhoto: function(){ // 打开相册方法  
            var that = this;  
            plus.gallery.pick(function(path) { // 从系统相册选择图片  
                that.rotateImg(path);             
            }, function(error) {  
                that.o.error(error);  
                console.log("---" + "捕获图像失败: " + error.message);  
            })  
        },  
        rotateImg: function(p) { // 图片处理方法(包括旋转,因在IOS中会有图片读取时会自动旋转,导致读取后的文件不正确)  
            var that = this;  
            if(p.indexOf('http') < 0) {  
                plus.zip.compressImage({  
                    src: p,  
                    dst: p,  
                    overwrite: true,  
                    rotate: 0 // 不管有没有被旋转,统一旋转0度  
                }, function(e) {  
                    if(mui.os.ios){ // 此处IOS需做路径转换处理,在转换时利用文件对象再去转base64,而安卓则直接可以用路径去加载文件  
                        plus.io.resolveLocalFileSystemURL(e.target, function(entry){  
                            entry.file(function(path){  
                                console.log("P__" + JSON.stringify(path));  
                                that.getBase64(path, e.target);   
                            })  
                        });   
                    } else{  
                        that.getBase64(e.target, e.target);  
                    }  
                }, function(error) {  
                    that.o.error(error);  
                    console.log("图片旋转时发生错误!");  
                });  
            } else {  
                that.o.success(p); // 如遇http地址,则直接返回该地址;  
            }  

        },  
        getBase64: function(path, url){                     // 获取Base64  
            var that = this;  
            var reader = new plus.io.FileReader();          // 构建文件对象  
            reader.readAsDataURL(path);                     // 添加文件(此处安卓可以直接添加文件路径,而IOS则需要文件对象)  
            reader.onloadend = function (event) {           // 文件加载 完成后的事件回调  
                //console.log('event'+JSON.stringify(event));  
                that.o.success(url, event.target.result);   // 执行成功函数,统一把路径及base64传过去  
            };  
        }  

    }  

})(window)
收起阅读 »

【讲座】html5+ App开发之 Android 平台离线集成 5+ SDK

技术分享

内容简介:

html5+ App开发过程中有时候会遇到一些功能,单纯通过 html5 或者 5+ 规范无法满足要求,比如自定义相机这种定制性较强的功能,这时候不得不借助第三方库或者原生插件来完成,本次讲座主要面向的就是需要定制性开发的朋友。

本次讲座的主要内容:

简单介绍 Android 开发环境
html5+ SDK 两种集成方式实例讲解
浅析 Android 原生 和 JavaScript 交互原理
Native.js 实例讲解
html5+ 插件开发实例详解
本节课时长80分钟左右。

面向人群:

想学习原生开发的前端开发朋友
想快速集成 5+ sdk 的原生开发朋友

报名地址:https://segmentfault.com/l/1500000010042078?r=bPqXdU

上次参与讲座的或者有兴趣但是经济有限的朋友(如学生),可以私聊我获取半价券!!!

继续阅读 »

内容简介:

html5+ App开发过程中有时候会遇到一些功能,单纯通过 html5 或者 5+ 规范无法满足要求,比如自定义相机这种定制性较强的功能,这时候不得不借助第三方库或者原生插件来完成,本次讲座主要面向的就是需要定制性开发的朋友。

本次讲座的主要内容:

简单介绍 Android 开发环境
html5+ SDK 两种集成方式实例讲解
浅析 Android 原生 和 JavaScript 交互原理
Native.js 实例讲解
html5+ 插件开发实例详解
本节课时长80分钟左右。

面向人群:

想学习原生开发的前端开发朋友
想快速集成 5+ sdk 的原生开发朋友

报名地址:https://segmentfault.com/l/1500000010042078?r=bPqXdU

上次参与讲座的或者有兴趣但是经济有限的朋友(如学生),可以私聊我获取半价券!!!

收起阅读 »

阿里百川插件集成,离线打包指导

外包

阿里百川插件集成,离线打包指导,需要请联系 qq: 37894663 源码打包,随时调试 非云打包 长期技术支持,解决各种前端疑难

阿里百川插件集成,离线打包指导,需要请联系 qq: 37894663 源码打包,随时调试 非云打包 长期技术支持,解决各种前端疑难

跪求:HBuilder mac版 8.1.3左右版本

最近因公司新项目需要,要求HBuilder必须是8.1.3.20170513左右的版本,谁有,跪求呀,急!
哪会小伙伴有,可以发我邮箱,谢谢~
908026301@qq.com

最近因公司新项目需要,要求HBuilder必须是8.1.3.20170513左右的版本,谁有,跪求呀,急!
哪会小伙伴有,可以发我邮箱,谢谢~
908026301@qq.com

父页面加载子页面,需要在父页面中动态创建子页面,然后在子页面加载完之后,显示子页面页面

//父页面中填写如下代码
$.plusReady(function() {

            //动态添加子页面,子页面加载事件完成之后,在show父页面  
            var mainView=plus.webview.currentWebview();  
            var subView=plus.webview.create("goodsList.html","sub",{  
                top:'258px',  
                bottom:0  
            })  
            mainView.append(subView);  
            subView.addEventListener("loaded",function(){  
                subView.show();  
            });  

});

继续阅读 »

//父页面中填写如下代码
$.plusReady(function() {

            //动态添加子页面,子页面加载事件完成之后,在show父页面  
            var mainView=plus.webview.currentWebview();  
            var subView=plus.webview.create("goodsList.html","sub",{  
                top:'258px',  
                bottom:0  
            })  
            mainView.append(subView);  
            subView.addEventListener("loaded",function(){  
                subView.show();  
            });  

});

收起阅读 »

基于Mui的Vue组件库

UI Vue mui

vue-awesome-mui

Design Mui library for Vuejs 2.0

Links

Install

Install vue-awesome-mui

npm install vue-awesome-mui -save

Get Started

Vue mount

// import or require  
import Vue from 'vue'  
import Mui from 'vue-awesome-mui'  
import 'vue-awesome-mui/mui/dist/css/mui.css'  
// mount with global  
Vue.use(Mui)

If you need icon, you can require icon.css

import "vue-awesome-mui/mui/examples/hello-mui/css/icons-extra.css";

Example

Give a few examples

折叠面板 Accordion

操作表 Actionsheet

数字角标 Badges

按钮 Buttons

Browser Support

  • IE 10+
  • Andorid 4.4+
  • IOS 7+

Changelog

Detailed changes for each release are documented in the release notes.

Contribution

Please make sure to read the Contributing Guide before making a pull request.

Dependencies

Licence

vue-awesome-mui is open source and released under the MIT Licence.

Copyright (c) 2017 Wscats

About author

继续阅读 »

vue-awesome-mui

Design Mui library for Vuejs 2.0

Links

Install

Install vue-awesome-mui

npm install vue-awesome-mui -save

Get Started

Vue mount

// import or require  
import Vue from 'vue'  
import Mui from 'vue-awesome-mui'  
import 'vue-awesome-mui/mui/dist/css/mui.css'  
// mount with global  
Vue.use(Mui)

If you need icon, you can require icon.css

import "vue-awesome-mui/mui/examples/hello-mui/css/icons-extra.css";

Example

Give a few examples

折叠面板 Accordion

操作表 Actionsheet

数字角标 Badges

按钮 Buttons

Browser Support

  • IE 10+
  • Andorid 4.4+
  • IOS 7+

Changelog

Detailed changes for each release are documented in the release notes.

Contribution

Please make sure to read the Contributing Guide before making a pull request.

Dependencies

Licence

vue-awesome-mui is open source and released under the MIT Licence.

Copyright (c) 2017 Wscats

About author

收起阅读 »

有问必答,小问题无偿 大问题有偿

外包

有问必答,小问题简单问题免费解决 大问题复杂问题有偿解决(望理解) 承接开发各种第三方插件 app 项目 及 离线打包指导等等。 需要联系 qq : 37894663

有问必答,小问题简单问题免费解决 大问题复杂问题有偿解决(望理解) 承接开发各种第三方插件 app 项目 及 离线打包指导等等。 需要联系 qq : 37894663