- 浏览: 1489750 次
- 性别:
- 来自: 北京
-
文章分类
- 全部博客 (691)
- linux (207)
- shell (33)
- java (42)
- 其他 (22)
- javascript (33)
- cloud (16)
- python (33)
- c (48)
- sql (12)
- 工具 (6)
- 缓存 (16)
- ubuntu (7)
- perl (3)
- lua (2)
- 超级有用 (2)
- 服务器 (2)
- mac (22)
- nginx (34)
- php (2)
- 内核 (2)
- gdb (13)
- ICTCLAS (2)
- mac android (0)
- unix (1)
- android (1)
- vim (1)
- epoll (1)
- ios (21)
- mysql (3)
- systemtap (1)
- 算法 (2)
- 汇编 (2)
- arm (3)
- 我的数据结构 (8)
- websocket (12)
- hadoop (5)
- thrift (2)
- hbase (1)
- graphviz (1)
- redis (1)
- raspberry (2)
- qemu (31)
- opencv (4)
- socket (1)
- opengl (1)
- ibeacons (1)
- emacs (6)
- openstack (24)
- docker (1)
- webrtc (11)
- angularjs (2)
- neutron (23)
- jslinux (18)
- 网络 (13)
- tap (9)
- tensorflow (8)
- nlu (4)
- asm.js (5)
- sip (3)
- xl2tp (5)
- conda (1)
- emscripten (6)
- ffmpeg (10)
- srt (1)
- wasm (5)
- bert (3)
- kaldi (4)
- 知识图谱 (1)
最新评论
-
wahahachuang8:
我喜欢代码简洁易读,服务稳定的推送服务,前段时间研究了一下go ...
websocket的helloworld -
q114687576:
http://www.blue-zero.com/WebSoc ...
websocket的helloworld -
zhaoyanzimm:
感谢您的分享,给我提供了很大的帮助,在使用过程中发现了一个问题 ...
nginx的helloworld模块的helloworld -
haoningabc:
leebyte 写道太NB了,期待早日用上Killinux!么 ...
qemu+emacs+gdb调试内核 -
leebyte:
太NB了,期待早日用上Killinux!
qemu+emacs+gdb调试内核
getImageFile()获取网络图片
showImage()加载本地indexedDB图片
showImage()加载本地indexedDB图片
<html > <head><meta charset="UTF-8"></head> <body onload="showImage()"> <pre> 通过chrome://indexeddb-internals/# 查看indexdb的存储路径,可以手动删除做测试 基本内容:http://www.ruanyifeng.com/blog/2018/07/indexeddb.html https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API/Using_IndexedDB 例子: https://hacks.mozilla.org/2012/02/storing-images-and-files-in-indexeddb/ http://robnyman.github.io/html5demos/indexeddb/ </pre> <input type="button" value="load picture" onclick="getImageFile()"/> <input type="button" value="show picture" onclick="showImage()"/> <figure> <img id="elephant" alt="A close up of an elephant"> <figcaption>A mighty big elephant, and mighty close too!</figcaption> </figure> <script type="text/javascript"> var indexedDB = window.indexedDB || window.webkitIndexedDB || window.mozIndexedDB || window.OIndexedDB || window.msIndexedDB, IDBTransaction = window.IDBTransaction || window.webkitIDBTransaction || window.OIDBTransaction || window.msIDBTransaction, dbVersion = 1.0; function getImageFile(){ var request = indexedDB.open("elephantFiles", dbVersion), db, createObjectStore = function (dataBase) { console.log("Creating objectStore") dataBase.createObjectStore("elephants"); }, putElephantInDb = function(blob){ console.log("Putting elephants in IndexedDB"); // Open a transaction to the database var readWriteMode = typeof IDBTransaction.READ_WRITE == "undefined" ? "readwrite" : IDBTransaction.READ_WRITE; var transaction = db.transaction(["elephants"], readWriteMode); // Put the blob into the dabase var put = transaction.objectStore("elephants").put(blob, "image"); }; request.onerror = function (event) { console.log("Error creating/accessing IndexedDB database"); }; request.onsuccess = function (event) { console.log("Success creating/accessing IndexedDB database"); db = request.result; db.onerror = function (event) { console.log("Error creating/accessing IndexedDB database"); }; // Create XHR var xhr = new XMLHttpRequest(), blob; xhr.open("GET", "elephant.png", true); // Set the responseType to blob xhr.responseType = "blob"; xhr.addEventListener("load", function () { if (xhr.status === 200) { console.log("Image retrieved"); // Blob as response blob = xhr.response; console.log("Blob:" + blob); // Put the received blob into IndexedDB putElephantInDb(blob); } }, false); // Send XHR xhr.send(); } // For future use. Currently only in latest Firefox versions request.onupgradeneeded = function (event) { createObjectStore(event.target.result); }; } function showImage() { // Create/open database var request = indexedDB.open("elephantFiles", dbVersion), db, showImage = function (){ console.log("showImage elephants in IndexedDB"); // Open a transaction to the database var readWriteMode = typeof IDBTransaction.READ_WRITE == "undefined" ? "readwrite" : IDBTransaction.READ_WRITE; var transaction = db.transaction(["elephants"], readWriteMode); transaction.objectStore("elephants").get("image").onsuccess = function (event) { var imgFile = event.target.result; console.log("Got elephant!" + imgFile); // Get window.URL object var URL = window.URL || window.webkitURL; // Create and revoke ObjectURL var imgURL = URL.createObjectURL(imgFile); // Set img src to ObjectURL var imgElephant = document.getElementById("elephant"); imgElephant.setAttribute("src", imgURL); // Revoking ObjectURL imgElephant.onload = function() { console.log("imgURL:"+imgURL) console.log("this.src:"+this.src) window.URL.revokeObjectURL(this.src); } }; }; request.onerror = function (event) { console.log("Error creating/accessing IndexedDB database"); }; request.onsuccess = function (event) { console.log("Success creating/accessing IndexedDB database"); db = request.result; db.onerror = function (event) { console.log("Error creating/accessing IndexedDB database"); }; // Interim solution for Google Chrome to create an objectStore. Will be deprecated if (db.setVersion) { if (db.version != dbVersion) { var setVersion = db.setVersion(dbVersion); setVersion.onsuccess = function () { showImage(); }; }else { showImage(); } }else { showImage(); } } // For future use. Currently only in latest Firefox versions request.onupgradeneeded = function (event) { //createObjectStore(event.target.result); }; } </script> </body> </html>
发表评论
-
vizceral-example的例子
2020-03-19 18:53 370自定义图和加载结构 代码在 https://github.c ... -
jsonpath的helloworld
2020-03-17 14:58 423基本语法:https://www.cnblogs.com/jp ... -
流动图神器vizceral
2019-10-12 19:04 543把c的代码生成json:https://github.com/ ... -
emscripten asm.js的helloworld
2018-03-01 20:15 1131mac下安装: brew install SDL2 SDL2_ ... -
websocket上传文件
2016-12-15 13:30 4513nginx的上传 查看http://haoningabc.it ... -
webpack的helloworld
2016-11-02 10:42 923参考 http://www.jianshu.com/p/42e ... -
iphone6等移动端的css自适应
2016-10-17 01:18 1222参考 http://jingyan.baidu.com/art ... -
javascript自定义事件
2016-06-01 21:49 563一言不合上代码 <input value=" ... -
html5的fiesystem api 浏览器本地存储
2016-06-01 15:59 932html5的fiesystem api可以存取本地文件 一言不 ... -
websocket传传图片
2015-12-25 17:51 7256参考[url]http://www.adobe.com/dev ... -
angularjs使用include后双向绑定失败的解决
2015-12-20 19:41 1880原理参考 http://segmentfault.com/q/ ... -
html5 陀螺仪
2014-11-26 21:05 5896<html> <head> ... -
webgl的贝塞尔曲线
2014-11-12 00:56 2550BezierCurve webgl的贝塞尔曲线 webgl ... -
chrome app的helloworld
2014-11-11 13:56 728参考 http://blog.csdn.net/rydiy/a ... -
shader and Program编程基本概念 - 转
2014-11-04 11:50 1570原地址:http://blog.csdn.net/myarro ... -
javascript对象转json
2014-10-17 14:09 1020<html> <head>& ... -
jquery 的svg中国地图
2012-12-16 14:37 28112三种吧 1.d3.js很强大 2.jquery的 jvecto ... -
纯css的树型结构
2012-10-03 18:29 1295<html><head> ... -
D3 的3d图
2012-09-16 17:05 1468LCF http://mathworld.wolfram. ... -
jquery table拖拽排序
2012-07-14 21:45 7137参考http://dragsort.codeplex.com/ ...
相关推荐
- **本地存储**:利用localStorage或IndexedDB缓存用户购物车信息,确保页面刷新后数据不丢失。 - **API接口**:与后台服务器交互,获取商品信息、完成购买操作等,需设计合理的API接口协议。 - **错误处理**:...
8. 数据存储:如果用户试穿记录需要保存,可能需要用到本地存储(如Web Storage或IndexedDB)。 通过分析这个压缩包的内容,开发者可以学习到如何创建一个互动式的虚拟试衣间,以及网页开发中涉及的各种技术细节。...
2. **数据管理**:通过本地存储或IndexedDB等技术,JavaScript可以保存用户的库存数据,即使在页面刷新后也能保持状态。 3. **实时更新**:通过WebSocket或者轮询(polling)技术,实现库存信息的实时同步,确保...
例如,`<header>`、`<footer>`、`<section>`等标签用于组织页面结构,Web Storage和IndexedDB提供本地数据存储,Canvas和SVG用于动态图形和动画。 2. **响应式设计**:H5移动端商城需采用响应式设计,确保在不同...
1. **离线存储**:通过`localStorage`和`IndexedDB`,实现用户数据的本地存储,提高页面加载速度和用户体验。 2. **媒体元素**:利用`<video>`和`<audio>`标签,支持多媒体内容的直接播放,增强购物体验。 3. **...