利用微信的weui框架上傳、預覽和刪除圖片

jQuery WeUI 是專為微信公眾賬號開發而設計的一個框架,jQuery WeUI的官網:http://jqweui.com/

需求:需要在微信公眾號網頁添加上傳圖片功能

技術選型:實現上傳圖片功能可選百度的WebUploader、餓了么的Element和微信的jQuery WeUI,WebUploader的缺點是自定義UI困難,自定義上傳過程困難,Element的缺點是Web 控件,與手機端樣式不符,而jQuery WeUI專門為微信公眾號做的框架,基本不會出現問題,使用起來比較簡單。最后當然就選微信的jQuery WeUI

HTML部分:

[html]?view plaincopy
  1. <!--圖片上傳-->??
  2. ????????<div?class="weui-gallery"?id="gallery">??
  3. ????????????<span?class="weui-gallery__img"?id="galleryImg"></span>??
  4. ????????????<div?class="weui-gallery__opr">??
  5. ????????????????<a?href="javascript:"?class="weui-gallery__del">??
  6. ????????????????????<i?class="weui-icon-delete?weui-icon_gallery-delete"></i>??
  7. ????????????????</a>??
  8. ????????????</div>??
  9. ????????</div>??
  10. ????????<div?class="weui-cells?weui-cells_form">??
  11. ????????????<div?class="weui-cell">??
  12. ????????????????<div?class="weui-cell__bd">??
  13. ????????????????????<div?class="weui-uploader">??
  14. ????????????????????????<div?class="weui-uploader__hd">??
  15. ????????????????????????????<p?class="weui-uploader__title">圖片上傳</p>??
  16. ????????????????????????</div>??
  17. ????????????????????????<div?class="weui-uploader__bd">??
  18. ????????????????????????????<ul?class="weui-uploader__files"?id="uploaderFiles">??
  19. ??????????????????????????????????
  20. ????????????????????????????</ul>??
  21. ????????????????????????????<div?class="weui-uploader__input-box">??
  22. ????????????????????????????????<input?id="uploaderInput"?class="weui-uploader__input?zjxfjs_file"?type="file"?accept="image/*"?multiple="">??
  23. ????????????????????????????</div>??
  24. ????????????????????????</div>??
  25. ????????????????????</div>??
  26. ????????????????</div>??
  27. ????????????</div>??
  28. ????????</div>??

JS部分:

[html]?view plaincopy
  1. <script?type="text/javascript"?src="../js/mui.min.js"></script>??
  2. <script?type="text/javascript"?src="../js/jquery.min.js"></script>??
  3. <script?src="../js/jquery-weui.min.js"></script>??
  4. <script>??
  5. ????mui.init();??
  6. ????$(function()?{??
  7. ????????var?tmpl?=?'<li?class="weui-uploader__file"?style="background-image:url(#url#)"></li>',??
  8. ????????????$gallery?=?$("#gallery"),??
  9. ????????????$galleryImg?=?$("#galleryImg"),??
  10. ????????????$uploaderInput?=?$("#uploaderInput"),??
  11. ????????????$uploaderFiles?=?$("#uploaderFiles");??
  12. ??
  13. ????????????$uploaderInput.on("change",?function(e)?{??
  14. ????????????????var?src,?url?=?window.URL?||?window.webkitURL?||?window.mozURL,??
  15. ????????????????files?=?e.target.files;??
  16. ????????????????for(var?i?=?0,?len?=?files.length;?i?<?len;?++i)?{??
  17. ????????????????????var?file?=?files[i];??
  18. ??
  19. ????????????????????if(url)?{??
  20. ????????????????????????src?=?url.createObjectURL(file);??
  21. ????????????????????}?else?{??
  22. ????????????????????????src?=?e.target.result;??
  23. ????????????????????}??
  24. ??
  25. ????????????????????$uploaderFiles.append($(tmpl.replace('#url#',?src)));??
  26. ????????????????}??
  27. ????????????});??
  28. ????????var?index;?//第幾張圖片??
  29. ????????$uploaderFiles.on("click",?"li",?function()?{??
  30. ????????????index?=?$(this).index();??
  31. ????????????$galleryImg.attr("style",?this.getAttribute("style"));??
  32. ????????????$gallery.fadeIn(100);??
  33. ????????});??
  34. ????????$gallery.on("click",?function()?{??
  35. ????????????$gallery.fadeOut(100);??
  36. ????????});??
  37. ????????//刪除圖片??
  38. ????????$(".weui-gallery__del").click(function()?{??
  39. ????????????$uploaderFiles.find("li").eq(index).remove();??
  40. ????????});??
  41. ????});??
  42. </script>??

CSS和JS文件可以去官網下載

[html]?view plaincopy
  1. <link?rel="stylesheet"?href="../css/mui.min.css">??
  2. <link?rel="stylesheet"?href="../css/weui.min.css"/>??
  3. <link?rel="stylesheet"?href="../css/jquery-weui.min.css"/>??
[html]?view plaincopy
  1. ?<script?type="text/javascript"?src="../js/mui.min.js"></script>??
  2. ?<script?type="text/javascript"?src="../js/jquery.min.js"></script>??
  3. ?<script?src="../js/jquery-weui.min.js"></script>??

效果圖:

點擊加號,上傳圖片

點擊圖片,可以進行預覽、刪除



本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/387140.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/387140.shtml
英文地址,請注明出處:http://en.pswp.cn/news/387140.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

【轉】Java Socket編程基礎及深入講解

原文&#xff1a;https://www.cnblogs.com/yiwangzhibujian/p/7107785.html#q2.3.3 Socket是Java網絡編程的基礎&#xff0c;了解還是有好處的&#xff0c; 這篇文章主要講解Socket的基礎編程。Socket用在哪呢&#xff0c;主要用在進程間&#xff0c;網絡間通信。本篇比較長&am…

使用 vue-i18n 切換中英文

使用 vue-i18n 切換中英文vue-i18n 倉庫地址&#xff1a;https://github.com/kazupon/vue-i18n兼容性&#xff1a;支持 Vue.js 2.x 以上版本安裝方法&#xff1a;&#xff08;此處只演示 npm&#xff09;npm install vue-i18n使用方法&#xff1a;1、在 main.js 中引入 vue-i18…

ZooKeeper數據模型

Zookeeper的數據模型 層次化的目錄結構&#xff0c;命名符合常規文件系統規范&#xff08;Linux&#xff09; 每個節點在zookeeper中叫做znode,并且其有一個唯一的路徑標識 節點Znode可以包含數據和子節點(即子目錄)&#xff0c;但是EPHEMERAL類型的節點不能有子節點 Znod…

堆疊條形圖

堆疊條形圖 import pandas as pd import numpy as np import matplotlib.pyplot as plt import matplotlib as mpl import matplotlib.dates as mdates#解決能顯示中文 mpl.rcParams[font.sans-serif][SimHei] #指定默認字體 SimHei為黑體 mpl.rcParams[axes.unicode_minus]Fal…

spring boot 服務器常用

ps aux|grep tgcwll /opt/nginx/html sudo cp -r /tmp/tgcw/dist/* /opt/nginx/html/design sudo cp -r /tmp/tgcw/dist/* /opt/nginx/html springboot 啟動nohup java -jar tgcw-service-usermanagement-0.0.1-SNAPSHOT.jar --spring.profiles.activedemo > /dev/null 2&g…

PHP數組 轉 對象/對象 轉 數組

/*** 數組 轉 對象** param array $arr 數組* return object*/ function array_to_object($arr) {if (gettype($arr) ! array) {return;}foreach ($arr as $k > $v) {if (gettype($v) array || getType($v) object) {$arr[$k] (object)array_to_object($v);}}return (obj…

ZooKeeper編程01--RMI服務的多服務器管理

服務器端與客戶端都要用到&#xff1a; public interface ZkInfo {String ZK_CONNECTION_STRING "192.168.1.201:2181,192.168.1.202:2181,192.168.1.203:2181";int ZK_SESSION_TIMEOUT 5000;String ZK_REGISTRY_PATH "/registry";String ZK_PROVIDER_…

org.activiti.engine.ActivitiOptimisticLockingException updated by another transaction concurrently

org.activiti.engine.ActivitiOptimisticLockingException: Task[id5905010, name審核(市場部)] was updated by another transaction concurrentlyat org.activiti.engine.impl.db.DbSqlSession.flushUpdates(DbSqlSession.java:872)at org.activiti.engine.impl.db.DbSqlSess…

DataTable不能通過已刪除的行訪問該行的信息解決方法

使用dt.Rows[0]["name", DataRowVersion.Original]可以獲取轉載于:https://www.cnblogs.com/heyiping/p/10616640.html

ZooKeeper編程02--多線程的分佈式鎖

面向過程版&#xff1a; package distributedLockProcess;import java.util.Collections; import java.util.List; import java.util.concurrent.CountDownLatch;import org.apache.zookeeper.CreateMode; import org.apache.zookeeper.KeeperException; import org.apache.zoo…

01 Python變量和數據類型

Python變量和數據類型 1 數據類型 計算機&#xff0c;顧名思義就是可以做數學計算的機器&#xff0c;因此&#xff0c;計算機程序理所當然也可以處理各種數值。 但是&#xff0c;計算機能處理的遠不止數值&#xff0c;還可以處理文本、圖形、音頻、視頻、網頁等各種各樣的數…

初識Python-1

1&#xff0c;計算機基礎。 2&#xff0c;python歷史。 宏觀上&#xff1a;python2 與 python3 區別&#xff1a; python2 源碼不標準&#xff0c;混亂&#xff0c;重復代碼太多&#xff0c; python3 統一 標準&#xff0c;去除重復代碼。 3&#xff0c;python的環境。 編譯型&…

02 List、Tuple、Dict、Set

List 線性表 創建List&#xff1a; >>> classmates [Michael, Bob, Tracy] >>> L [Michael, 100, True] #可以在list中包含各種類型的數據 >>> empty_list [] #空List 按索引訪問List&#xff1a; >>> print L[0] #索引從0開始…

Jenkins的一些代碼

pipeline {agent anyenvironment { def ITEMNAME "erp"def DESTPATH "/home/ops/testpipe"def codePATH"/var/lib/jenkins/workspace/test_pipeline"}stages { stage(代碼拉取){steps {echo "checkout from ${ITEMNAME}"git url:…

利用layui前端框架實現對不同文件夾的多文件上傳

利用layui前端框架實現對不同文件夾的多文件上傳 問題場景&#xff1a; 普通的input標簽實現多文件上傳時&#xff0c;只能對同一個文件夾下的多個文件進行上傳&#xff0c;如果要同時上傳兩個或多個文件夾下的文件&#xff0c;是無法實現的。這篇文章就是利用layui中的插件&am…

ps、grep和kill聯合使用殺掉進程

ps、grep和kill聯合使用殺掉進程例如要殺掉hello這個進程&#xff0c;使用下面這個命令就能直接實現。ps -ef |grep hello |awk {print $2}|xargs kill -9這里是輸出ps -ef |grep hello 結果的第二列的內容然后通過xargs傳遞給kill -9,其實第二列內容就是hello的進程號&#xf…

03 控制語句

if語句 if age > 18 print your age is, age else print teenager Python代碼的縮進規則&#xff1a;具有相同縮進的代碼被視為代碼塊。 if age > 18 print adult elif age > 6 print teenager elif age > 3 print kid else print baby for循環 L [Adam, L…

yum 來安裝 nodejs

要通過 yum 來安裝 nodejs 和 npm 需要先給 yum 添加 epel 源&#xff0c;添加方法在 centos 添加epel和remi源 中##添加 epel 源 64位: rpm -ivh http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm32位: rpm -ivh http://download.fedoraproj…

yzh的神仙題

U66905 zz題 考慮一個點權值被計算了多少次。。。不知 所以對未來承諾&#xff0c;方便直接算上總數&#xff01; 然后其實是給邊定向&#xff0c;即先刪除fa和son的哪一個 f[x][j]&#xff0c;會計算j次 無法轉移 f[x][j][k]&#xff0c;其中會從子樹計算k次。 當邊從兒子指向…

04 函數

內置函數 Python內置了很多有用的函數&#xff0c;可以直接調用。 要調用一個函數&#xff0c;需要知道函數的名稱和參數。 可以直接從Python的官方網站查看文檔&#xff1a;http://docs.python.org/2/library >>> abs(-20) >>> help(abs) >>>…