本文主要包含mui相册,mui 上传头像,mui 修改头像,mui 更换头像,mui等相关知识,教程希望在学习及工作中可以帮助到您
");
</div>
html部分:
js部分:
- <img class="mui-media-object mui-pull-left head-img" id="head-img" src="img/head.png">
- /*点击头像触发*/
- document.getElementById('head').addEventListener('tap', function() {
- if(mui.os.plus) {
- var a = [{
- title: "拍照"
- }, {
- title: "从手机相册选择"
- }];
- plus.nativeUI.actionSheet({
- title: "修改用户头像",
- cancel: "取消",
- buttons: a
- }, function(b) { /*actionSheet 按钮点击事件*/
- switch(b.index) {
- case 0:
- break;
- case 1:
- getImage(); /*拍照*/
- break;
- case 2:
- galleryImg(); /*打开相册*/
- break;
- default:
- break;
- }
- })
- }
- }, false);
- //拍照
- function getImage() {
- var cmr = plus.camera.getCamera();
- var res = cmr.supportedImageResolutions[0];
- var fmt = cmr.supportedImageFormats[0];
- cmr.captureImage(function(path) {
- //plus.io.resolveLocalFileSystemURL(path, function(entry) {
- plus.io.resolveLocalFileSystemURL(path, function(entry) {
- var localUrl = entry.toLocalURL();
- uploadHead(localUrl + "?version=" + new Date().getTime());
- }, function(err) {
- console.error("拍照失败:" + err.message);
- }, {
- index: 1
- });
- });
- }
- //本地相册选择
- function galleryImg() {
- plus.gallery.pick(function(a) {
- plus.io.resolveLocalFileSystemURL(a, function(entry) {
- plus.io.resolveLocalFileSystemURL("_doc/", function(root) {
- root.getFile("head.png", {}, function(file) {
- //文件