﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-xiaomage234-随笔分类-html5</title><link>http://www.blogjava.net/xiaomage234/category/50778.html</link><description>生命本就是一次凄美的漂流，记忆中放不下的，永远是孩提时代的那一份浪漫与纯真！</description><language>zh-cn</language><lastBuildDate>Mon, 03 Sep 2012 19:47:00 GMT</lastBuildDate><pubDate>Mon, 03 Sep 2012 19:47:00 GMT</pubDate><ttl>60</ttl><item><title>Chrome浏览器上的语音输入功能</title><link>http://www.blogjava.net/xiaomage234/archive/2012/09/03/386842.html</link><dc:creator>小马歌</dc:creator><author>小马歌</author><pubDate>Mon, 03 Sep 2012 02:24:00 GMT</pubDate><guid>http://www.blogjava.net/xiaomage234/archive/2012/09/03/386842.html</guid><wfw:comment>http://www.blogjava.net/xiaomage234/comments/386842.html</wfw:comment><comments>http://www.blogjava.net/xiaomage234/archive/2012/09/03/386842.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/xiaomage234/comments/commentRss/386842.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/xiaomage234/services/trackbacks/386842.html</trackback:ping><description><![CDATA[<div><p>&nbsp;使用Chrome浏览器的同学应该会经常看到一些网站的搜索框右边有一个麦克风的标志，点击图标后即可连接麦克风进行语音识别搜索，那么这是如何实现的呢？</p><p><img src="http://www.huceo.com/weibo/upload/2012/6/taobaoyuyin.jpg" alt="淘宝网上的语音搜索功能" /></p><p>其实非常简单，这是html5下一个新的属性，通过调用google的语音服务api，用于支持网页内的语音识别输入功能。</p><p>只需要在输入框的input上添加一个<span style="color: #ff0000; ">x-webkit-speech</span>&nbsp;属性就可以了。</p><p>如本博客的搜索框：</p><p>&lt;input  type="text" &nbsp;name="edtSearch" x-webkit-speech id="edtSearch"  value="Search...." onfocus="if (this.value == 'Search....') {this.value =  '';}" onblur="if (this.value == '') {this.value = 'Search....';}" /&gt;</p><p>另外它还可以添加以下属性：</p><p>语言种类： lang="zh-CN"</p><p>发声改变时触发相关语音识别：onwebkitspeechchange="foo()"</p><p>让语音输入的内容更加精确尽量接近搜索内容：x-webkit-grammar="bUIltin:search"</p><p>通过平时的使用感觉如果发音清晰的话，识别率还算不错。这是google应用于Chrome浏览器上的一项实验性功能，以上属性同样也对webkit内核浏览器生效。</p><p>相关W3C标准参考文档：<a href="http://lists.w3.org/Archives/Public/public-xg-htmlspeech/2011Feb/att-0020/api-draft.html">http://lists.w3.org/Archives/Public/public-xg-htmlspeech/2011Feb/att-0020/api-draft.html</a></p></div><img src ="http://www.blogjava.net/xiaomage234/aggbug/386842.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/xiaomage234/" target="_blank">小马歌</a> 2012-09-03 10:24 <a href="http://www.blogjava.net/xiaomage234/archive/2012/09/03/386842.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>人人网首页拖拽上传详解(HTML5 Drag&amp;Drop、FileReader API、FormData) 【转】</title><link>http://www.blogjava.net/xiaomage234/archive/2012/03/19/372202.html</link><dc:creator>小马歌</dc:creator><author>小马歌</author><pubDate>Mon, 19 Mar 2012 08:35:00 GMT</pubDate><guid>http://www.blogjava.net/xiaomage234/archive/2012/03/19/372202.html</guid><wfw:comment>http://www.blogjava.net/xiaomage234/comments/372202.html</wfw:comment><comments>http://www.blogjava.net/xiaomage234/archive/2012/03/19/372202.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/xiaomage234/comments/commentRss/372202.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/xiaomage234/services/trackbacks/372202.html</trackback:ping><description><![CDATA[<p style="margin-top: 15px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; list-style-type: none; font-family: Arial, Helvetica, sans-serif, 瀹嬩綋; line-height: 24px; background-color: #fcf1f5; "><img size-full=""  wp-image-401"="" title="人人网首页拖拽上传详解" alt="人人网首页拖拽上传详解" width="620" height="260" src="http://www.kuqin.com/upimg/allimg/111212/231A03013-0.jpg" style="margin-top: 0px; margin-right: auto; margin-bottom: 10px; margin-left: auto; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; border-image: initial; float: none; text-align: center; clear: both; display: block; max-width: 580px; " /></p><p style="margin-top: 15px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; list-style-type: none; font-family: Arial, Helvetica, sans-serif, 瀹嬩綋; line-height: 24px; background-color: #fcf1f5; ">　　早在公元2011年6月3日傍晚，人人网推出了一个很装B且完全无视IE浏览器的功能&#8212;&#8212;拖拽上床。哦，Sorry, 是<strong>拖拽上传</strong>。本文将重点介绍实现拖拽上传的几个HTML5技术：<strong>Drag&amp;Drop</strong>、<strong>FileReader API</strong>和<strong>FormData</strong>。</p><p style="margin-top: 15px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; list-style-type: none; font-family: Arial, Helvetica, sans-serif, 瀹嬩綋; line-height: 24px; background-color: #fcf1f5; ">　　关于这个拖拽上传，其实国外有很多网站已经有这样的应用，最早推出拖拽上传应用的是Gmail，它支持标准浏览器下拖拽本地文件到浏览器中作为邮件的附件发送。人人网的这个拖拽上传也是同理，可以让使用标准浏览器的用户通过简单的拖拽行为，将本地文件夹中的照片直接上传到人人网，用户体验能得到提升的同时，也希望借此机会推广一下标准浏览器，淘汰IE。人人网当时也向广大用户推出升级浏览器活动，并喊出口号：&#8221;工欲善其计算机，必先利其浏览器&#8221;。本次拖拽上传的宣传口号：你敢&#8221;脱&#8221;，我就敢上传&#8230;</p><p style="margin-top: 15px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; list-style-type: none; font-family: Arial, Helvetica, sans-serif, 瀹嬩綋; line-height: 24px; background-color: #fcf1f5; "><a href="http://blog.bingo929.com/wp-content/uploads/2011/12/b_large_pbOj_3004000003b45c41.jpg" style="color: #800080; text-decoration: none; outline-style: none; "><img title="人人网 - 拖拽上传" alt="人人网 - 拖拽上传" width="500" height="259" src="http://www.kuqin.com/upimg/allimg/111212/231A04129-1.jpg" style="margin-top: 0px; margin-right: auto; margin-bottom: 0px; margin-left: auto; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; border-image: initial; border-width: initial; border-color: initial; max-width: 580px; display: block; " /></a></p><p style="margin-top: 15px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; list-style-type: none; font-family: Arial, Helvetica, sans-serif, 瀹嬩綋; line-height: 24px; background-color: #fcf1f5; ">　　言归正题，首先看看效果，大家如果有人人网帐号的话可以在首页试一试拖拽上传功能，下面是演示视频：</p><p style="margin-top: 15px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; list-style-type: none; font-family: Arial, Helvetica, sans-serif, 瀹嬩綋; line-height: 24px; background-color: #fcf1f5; "><object height="430" width="500" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"></object></p><p style="margin-top: 15px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; list-style-type: none; font-family: Arial, Helvetica, sans-serif, 瀹嬩綋; line-height: 24px; background-color: #fcf1f5; "><strong>拖拽上传应用主要使用了以下HTML5技术：</strong></p><ul style="margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 20px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; list-style-type: none; list-style-position: initial; list-style-image: initial; font-family: Arial, Helvetica, sans-serif, 瀹嬩綋; line-height: 24px; background-color: #fcf1f5; "><li style="margin-top: 0px; margin-right: auto; margin-bottom: 0px; margin-left: auto; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 20px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; list-style-type: none; list-style-position: initial; list-style-image: initial; background-image: url(http://www.kuqin.com/new/images/wz_d.png); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: no-repeat no-repeat; "><a target="_blank" href="http://dev.w3.org/html5/spec/Overview.html#dnd" style="color: #800080; text-decoration: none; outline-style: none; "><strong>Drag&amp;Drop</strong></a>&nbsp;: HTML5基于拖拽的事件机制.</li><li style="margin-top: 0px; margin-right: auto; margin-bottom: 0px; margin-left: auto; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 20px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; list-style-type: none; list-style-position: initial; list-style-image: initial; background-image: url(http://www.kuqin.com/new/images/wz_d.png); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: no-repeat no-repeat; "><a target="_blank" href="http://www.w3.org/TR/FileAPI/" style="color: #800080; text-decoration: none; outline-style: none; "><strong>File API</strong></a>&nbsp;: &nbsp;可以很方便的让Web应用访问文件对象，File API包括<a href="http://dev.w3.org/2006/webapi/FileAPI/#dfn-filelist" style="color: #800080; text-decoration: none; outline-style: none; ">FileList</a>、<a href="http://dev.w3.org/2006/webapi/FileAPI/#dfn-Blob" style="color: #800080; text-decoration: none; outline-style: none; ">Blob</a>、<a href="http://dev.w3.org/2006/webapi/FileAPI/#dfn-file" style="color: #800080; text-decoration: none; outline-style: none; ">File</a>、<a href="http://dev.w3.org/2006/webapi/FileAPI/#dfn-filereader" style="color: #800080; text-decoration: none; outline-style: none; ">FileReader</a>、<a href="http://dev.w3.org/2006/webapi/FileAPI/#url" style="color: #800080; text-decoration: none; outline-style: none; ">URI scheme</a>，本文主要讲解拖拽上传中用到的FileList和FileReader接口。</li><li style="margin-top: 0px; margin-right: auto; margin-bottom: 0px; margin-left: auto; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 20px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; list-style-type: none; list-style-position: initial; list-style-image: initial; background-image: url(http://www.kuqin.com/new/images/wz_d.png); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: no-repeat no-repeat; "><a target="_blank" href="http://www.w3.org/TR/XMLHttpRequest2/#the-formdata-interface" style="color: #800080; text-decoration: none; outline-style: none; "><strong>FormData</strong></a>&nbsp;: FormData是基于<a target="_blank" href="http://www.w3.org/TR/XMLHttpRequest2/" style="color: #800080; text-decoration: none; outline-style: none; ">XMLHttpRequest Level 2</a>的新接口，可以方便web应用模拟Form表单数据，最重要的是它支持文件的二进制流数据，这样我们就能够通过它来实现AJAX向后端发送文件数据了。</li></ul><h3><strong>HTML5 Drag&amp;Drop 拖拽事件</strong></h3><p style="margin-top: 15px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; list-style-type: none; font-family: Arial, Helvetica, sans-serif, 瀹嬩綋; line-height: 24px; background-color: #fcf1f5; ">　　关于Drag&amp;Drop拖拽事件，之前我写过一篇专门介绍的文章<a target="_blank" href="http://blog.bingo929.com/google-enjoy-html5-drag-drop-filereaderenren.html" style="color: #800080; text-decoration: none; outline-style: none; font-weight: bold; ">《给力的 Google HTML5 训练营(HTML5 Drag&amp;Drop 拖拽、FileReader实例教程)》</a>，那篇文章详细讲解了Drag &amp; Drap事件的原理和代码实例，这里的拖拽上传实现原理基本上是一样的，大家有兴趣或不太了解的话可以先看看那篇文章，我在这里就不再过多啰嗦了~下面直接出拖拽上传简要代码实例：</p><div style="font-family: Arial, Helvetica, sans-serif, 瀹嬩綋; line-height: 24px; background-color: #aaccf7; border-bottom-color: #111111; border-bottom-width: 1px; border-bottom-style: dashed; border-left-color: #111111; border-left-width: 1px; border-left-style: dashed; padding-bottom: 10px; padding-left: 10px; padding-right: 10px; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; color: #0d2742; border-top-color: #111111; border-top-width: 1px; border-top-style: dashed; border-right-color: #111111; border-right-width: 1px; border-right-style: dashed; padding-top: 10px; ">var oDragWrap = document.body;<p style="margin-top: 15px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; list-style-type: none; ">&nbsp;</p><p style="margin-top: 15px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; list-style-type: none; ">//拖进<br />oDragWrap.addEventListener(&#8217;dragenter&#8217;, function(e) {<br />　e.preventDefault();<br />}, false);</p><p style="margin-top: 15px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; list-style-type: none; ">//拖离<br />oDragWrap.addEventListener(&#8217;dragleave&#8217;, function(e) {<br />　dragleaveHandler(e);<br />}, false);</p><p style="margin-top: 15px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; list-style-type: none; ">//拖来拖去 , 一定要注意dragover事件一定要清除默认事件<br />//不然会无法触发后面的drop事件<br />oDragWrap.addEventListener(&#8217;dragover&#8217;, function(e) {<br />　e.preventDefault();<br />}, false);</p><p style="margin-top: 15px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; list-style-type: none; ">//扔<br />oDragWrap.addEventListener(&#8217;drop&#8217;, function(e) {<br />　dropHandler(e);<br />}, false);</p><p style="margin-top: 15px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; list-style-type: none; ">var dropHandler = function(e) {<br />//将本地图片拖拽到页面中后要进行的处理都在这<br />}</p></div><h3>获取文件数据 HTML5 File API</h3><p style="margin-top: 15px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; list-style-type: none; font-family: Arial, Helvetica, sans-serif, 瀹嬩綋; line-height: 24px; background-color: #fcf1f5; ">　　在之前<a target="_blank" href="http://blog.bingo929.com/google-enjoy-html5-drag-drop-filereaderenren.html" style="color: #800080; text-decoration: none; outline-style: none; ">那篇文章</a>中我也有介绍过关于File API中的FileReader接口，作为&nbsp;<a target="_blank" href="http://www.w3.org/TR/FileAPI/" style="color: #800080; text-decoration: none; outline-style: none; ">File API</a>&nbsp;的一部分，<a target="_blank" href="http://www.w3.org/TR/FileAPI/#dfn-filereader" style="color: #800080; text-decoration: none; outline-style: none; ">FileReader</a>&nbsp;专门用于读取文件，根据 W3C 的定义，FileReader 接口 &#8220;提供一些读取文件的方法与一个包含读取结果的事件模型&#8221;。关于FileReader的详细介绍和代码实例大家可以先去看看那篇<a target="_blank" href="http://blog.bingo929.com/google-enjoy-html5-drag-drop-filereaderenren.html" style="color: #800080; text-decoration: none; outline-style: none; ">文章</a>。</p><p style="margin-top: 15px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; list-style-type: none; font-family: Arial, Helvetica, sans-serif, 瀹嬩綋; line-height: 24px; background-color: #fcf1f5; ">　　今天我着重介绍一下File API中的FileList接口,它主要通过两个途径获取本地文件列表，一是<strong>&lt;input type=&#8221;file&#8221;&gt;</strong>的表单形式，另一种则是<strong>e.dataTransfer.files</strong>拖拽事件传递的文件信息。很显然，我们这里会用到后者。</p><div style="font-family: Arial, Helvetica, sans-serif, 瀹嬩綋; line-height: 24px; background-color: #aaccf7; border-bottom-color: #111111; border-bottom-width: 1px; border-bottom-style: dashed; border-left-color: #111111; border-left-width: 1px; border-left-style: dashed; padding-bottom: 10px; padding-left: 10px; padding-right: 10px; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; color: #0d2742; border-top-color: #111111; border-top-width: 1px; border-top-style: dashed; border-right-color: #111111; border-right-width: 1px; border-right-style: dashed; padding-top: 10px; ">var fileList = e.dataTransfer.files;</div><p style="margin-top: 15px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; list-style-type: none; font-family: Arial, Helvetica, sans-serif, 瀹嬩綋; line-height: 24px; background-color: #fcf1f5; ">　　使用<strong>files方法</strong>将会获取到拖拽文件的数组形势的数据，每个文件占用一个数组的索引，如果该索引不存在文件数据，将返回null值。可以通过<strong>length</strong>属性获取文件数量.</p><div style="font-family: Arial, Helvetica, sans-serif, 瀹嬩綋; line-height: 24px; background-color: #aaccf7; border-bottom-color: #111111; border-bottom-width: 1px; border-bottom-style: dashed; border-left-color: #111111; border-left-width: 1px; border-left-style: dashed; padding-bottom: 10px; padding-left: 10px; padding-right: 10px; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; color: #0d2742; border-top-color: #111111; border-top-width: 1px; border-top-style: dashed; border-right-color: #111111; border-right-width: 1px; border-right-style: dashed; padding-top: 10px; ">var fileNum = fileList.length;</div><p style="margin-top: 15px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; list-style-type: none; font-family: Arial, Helvetica, sans-serif, 瀹嬩綋; line-height: 24px; background-color: #fcf1f5; ">　　拖拽上传需要注意的是需要判断两个条件，1:拖拽的是文件不是页面中的元素; 2:拖拽的是图片而不是其它文件,可以通过file.type属性获取文件的类型</p><div style="font-family: Arial, Helvetica, sans-serif, 瀹嬩綋; line-height: 24px; background-color: #aaccf7; border-bottom-color: #111111; border-bottom-width: 1px; border-bottom-style: dashed; border-left-color: #111111; border-left-width: 1px; border-left-style: dashed; padding-bottom: 10px; padding-left: 10px; padding-right: 10px; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; color: #0d2742; border-top-color: #111111; border-top-width: 1px; border-top-style: dashed; border-right-color: #111111; border-right-width: 1px; border-right-style: dashed; padding-top: 10px; ">//检测是否是拖拽文件到页面的操作<br />if (fileList.length === 0) {return;};<br />//检测文件是不是图片<br />if (fileList[0].type.indexOf(&#8217;image&#8217;) === -1) {return;}</div><p style="margin-top: 15px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; list-style-type: none; font-family: Arial, Helvetica, sans-serif, 瀹嬩綋; line-height: 24px; background-color: #fcf1f5; ">　　下面让我们来看看如何结合之前的拖拽事件来实现拖拽图片并在页面中进行预览：</p><div style="font-family: Arial, Helvetica, sans-serif, 瀹嬩綋; line-height: 24px; background-color: #aaccf7; border-bottom-color: #111111; border-bottom-width: 1px; border-bottom-style: dashed; border-left-color: #111111; border-left-width: 1px; border-left-style: dashed; padding-bottom: 10px; padding-left: 10px; padding-right: 10px; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; color: #0d2742; border-top-color: #111111; border-top-width: 1px; border-top-style: dashed; border-right-color: #111111; border-right-width: 1px; border-right-style: dashed; padding-top: 10px; ">var dropHandler = function(e) {<br />　e.preventDefault();<p style="margin-top: 15px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; list-style-type: none; ">&nbsp;</p><p style="margin-top: 15px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; list-style-type: none; ">　//获取文件列表<br />　var fileList = e.dataTransfer.files;</p><p style="margin-top: 15px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; list-style-type: none; ">　//检测是否是拖拽文件到页面的操作<br />　if (fileList.length == 0) {return;};</p><p style="margin-top: 15px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; list-style-type: none; ">　//检测文件是不是图片<br />　if (fileList[0].type.indexOf(&#8217;image&#8217;) === -1) {return;}</p><p style="margin-top: 15px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; list-style-type: none; ">　//实例化file reader对象<br />　var reader = new FileReader();<br />　var img = document.createElement(&#8217;img&#8217;);</p><p style="margin-top: 15px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; list-style-type: none; ">　reader.onload = function(e) {<br />　　img.src = this.result;<br />　　oDragWrap.appendChild(img);<br />　}<br />　reader.readAsDataURL(fileList[0]);</p><p style="margin-top: 15px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; list-style-type: none; ">}</p></div><p style="margin-top: 15px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; list-style-type: none; font-family: Arial, Helvetica, sans-serif, 瀹嬩綋; line-height: 24px; background-color: #fcf1f5; ">　　这里有一个简单的<a target="_blank" href="http://www.bingo929.com/mytest/dragtest.html" style="color: #800080; text-decoration: none; outline-style: none; ">拖拽图片预览的Demo</a></p><p style="margin-top: 15px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; list-style-type: none; font-family: Arial, Helvetica, sans-serif, 瀹嬩綋; line-height: 24px; background-color: #fcf1f5; ">　　这时你如果用FireBug等类似调试工具查看DOM的话，会看到&lt;img&gt;标签的src属性是一个超长的文件二进制数据，所以如果DOM有很多这类图片，那就要当心浏览器性能了，因为这些数据极大地扩充的页面的代码量，而每次页面的reflow都会对浏览器形成很大的负担，So,如果这些图片还在DOM中，那就尽量不要做动画或任何重绘操作，如果真的要做就尽量让图片脱离文档流，让其绝对定位比较靠谱。</p><p style="margin-top: 15px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; list-style-type: none; font-family: Arial, Helvetica, sans-serif, 瀹嬩綋; line-height: 24px; background-color: #fff7d1; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; color: #d6006d; ">补充：可以使用<strong>window.URL.createObjectURL(file)</strong>来获取文件的URL(Chrome下用<strong>window.webkitURL.createObjectURL(file)</strong>)，这种方式获取的URL要比上面说的<strong>readAsDataURL</strong>简短很多。而且可以省去使用FileReader。这里感谢BinBinLiao的留言建议:) 下面是使用readAsDataURL与createObjectURL生成的<img alt="" style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; border-image: initial; max-width: 580px; " />代码对比：</p><p style="margin-top: 15px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; list-style-type: none; font-family: Arial, Helvetica, sans-serif, 瀹嬩綋; line-height: 24px; background-color: #fcf1f5; "><img size-full=""  wp-image-411"="" title="readAsDataURL与createObjectUrl对比" alt="readasdataurl-vs-createobjecturl" width="620" height="300" src="http://www.kuqin.com/upimg/allimg/111212/231A03P5-2.png" style="margin-top: 0px; margin-right: auto; margin-bottom: 10px; margin-left: auto; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; border-image: initial; float: none; text-align: center; clear: both; display: block; max-width: 580px; " /></p><p style="margin-top: 15px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; list-style-type: none; font-family: Arial, Helvetica, sans-serif, 瀹嬩綋; line-height: 24px; background-color: #fcf1f5; ">优化后的代码：(红色为优化的代码)</p><div style="font-family: Arial, Helvetica, sans-serif, 瀹嬩綋; line-height: 24px; background-color: #aaccf7; border-bottom-color: #111111; border-bottom-width: 1px; border-bottom-style: dashed; border-left-color: #111111; border-left-width: 1px; border-left-style: dashed; padding-bottom: 10px; padding-left: 10px; padding-right: 10px; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; color: #0d2742; border-top-color: #111111; border-top-width: 1px; border-top-style: dashed; border-right-color: #111111; border-right-width: 1px; border-right-style: dashed; padding-top: 10px; ">var dropHandler = function(e) {<br />　e.preventDefault();<p style="margin-top: 15px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; list-style-type: none; ">&nbsp;</p><p style="margin-top: 15px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; list-style-type: none; ">　var fileList = e.dataTransfer.files;　　//获取文件列表<br />　var img = document.createElement(&#8217;img&#8217;);</p><p style="margin-top: 15px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; list-style-type: none; ">　//检测是否是拖拽文件到页面的操作<br />　if (fileList.length == 0) {return;};</p><p style="margin-top: 15px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; list-style-type: none; ">　//检测文件是不是图片<br />　if (fileList[0].type.indexOf(&#8217;image&#8217;) === -1) {return;}<br />　</p><div style="color: #d6006d; ">　if (window.URL.createObjectURL) {<br />　　//FF4+<br />　　img.src = window.URL.createObjectURL(fileList[0]);<br />　} else if (window.webkitURL.createObjectURL) {<br />　　//Chrome8+<br />　　img.src = window.webkitURL.createObjectURL(fileList[0]);<br />　} else {<br />　　//实例化file reader对象<br />　　var reader = new FileReader();<p style="margin-top: 15px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; list-style-type: none; ">&nbsp;</p><p style="margin-top: 15px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; list-style-type: none; ">　　reader.onload = function(e) {<br />　　　img.src = this.result;<br />　　　oDragWrap.appendChild(img);<br />　　}<br />　　reader.readAsDataURL(fileList[0]);<br />　}</p></div><p style="margin-top: 15px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; list-style-type: none; ">}</p></div><p style="margin-top: 15px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; list-style-type: none; font-family: Arial, Helvetica, sans-serif, 瀹嬩綋; line-height: 24px; background-color: #fcf1f5; ">　　需要注意的是，window.URL.createObjectURL是有生命周期的，也就意味着你每用此方法获取URL，其生命周期都会和DOM一样，它会单独占用内存，所以当删除图片或不再需要它是，记得用window.URL.revokeObjectURL(file)来释放其内存。当然，如果你没有释放，刷新页面也是可以释放的。</p><h3>AJAX上传图片(file.getAsBinary &amp; FormData)</h3><p style="margin-top: 15px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; list-style-type: none; font-family: Arial, Helvetica, sans-serif, 瀹嬩綋; line-height: 24px; background-color: #fcf1f5; ">　　既然已经获取到了拖拽到web页面中图片的数据，下一步就是将其发送到服务器端了。</p><p style="margin-top: 15px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; list-style-type: none; font-family: Arial, Helvetica, sans-serif, 瀹嬩綋; line-height: 24px; background-color: #fcf1f5; ">　　话说HTML5时代之前，AJAX传输文件二进制流数据是不可能完成的事情，而现在我们完全可以通过<strong>file.getAsBinary</strong>获取文件的二进制数据流，进而将其当做XHR的data数据传送到后端，8过由于Chrome不支持file的getAsBinary方法，FF3.6+支持此方法。所以Chrome就要另寻它法了，这时我们发现<a target="_blank" href="http://www.w3.org/TR/XMLHttpRequest2/" style="color: #800080; text-decoration: none; outline-style: none; ">XMLHttpRequest Level 2</a>中的FormData接口完美解决了这个问题，它可以很快捷的模拟Form表单数据并通过AJAX发送至后端，FormData的支持情况是FF5及以上支持，Chrome12及以上支持。</p><p style="margin-top: 15px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; list-style-type: none; font-family: Arial, Helvetica, sans-serif, 瀹嬩綋; line-height: 24px; background-color: #fcf1f5; ">　　<strong>&nbsp;file.getAsBinary</strong>获取文件流很简单，但是要想上传数据，就要模拟一下表单的数据格式了，首先看看模拟表单的js代码,&nbsp;<strong>FormData</strong>模拟表单数据时更是简洁，不用麻烦的去拼字符串，而是直接将数据append到formdata对象中即可：</p><div style="font-family: Arial, Helvetica, sans-serif, 瀹嬩綋; line-height: 24px; background-color: #aaccf7; border-bottom-color: #111111; border-bottom-width: 1px; border-bottom-style: dashed; border-left-color: #111111; border-left-width: 1px; border-left-style: dashed; padding-bottom: 10px; padding-left: 10px; padding-right: 10px; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; color: #0d2742; border-top-color: #111111; border-top-width: 1px; border-top-style: dashed; border-right-color: #111111; border-right-width: 1px; border-right-style: dashed; padding-top: 10px; ">var xhr = new XMLHttpRequest();<br />var url = &#8216;http://upload.renren.com/&#8230;&#8230;&#8217;;<br />var boundary = &#8216;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;&#8217; + new Date().getTime();<br />var fileName = file.name;<p style="margin-top: 15px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; list-style-type: none; ">&nbsp;</p><p style="margin-top: 15px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; list-style-type: none; ">xhr.open(&#8221;post&#8221;, url, true);<br />xhr.setRequestHeader(&#8217;Content-Type&#8217;, &#8216;multipart/form-data; boundary=&#8217; + boundary);</p><p style="margin-top: 15px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; list-style-type: none; ">if (window.FormData) {<br />　//Chrome12+<br />　var formData = new FormData();<br />　formData.append(&#8217;file&#8217;, file);<br />　formData.append(&#8217;hostid&#8217;, userId);<br />　formData.append(&#8217;requestToken&#8217;, t);</p><p style="margin-top: 15px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; list-style-type: none; ">　data = formData;<br />} else if (file.getAsBinary) {<br />　//FireFox 3.6+<br />　data = &#8220;&#8211;&#8221; +<br />　boundary +<br />　crlf +<br />　&#8221;Content-Disposition: form-data; &#8221; +<br />　&#8221;name=\&#8221;" +<br />　&#8217;file&#8217; +<br />　&#8221;\&#8221;; &#8221; +<br />　&#8221;filename=\&#8221;" +<br />　unescape(encodeURIComponent(file.name)) +<br />　&#8221;\&#8221;" +<br />　crlf +<br />　&#8221;Content-Type: image/jpeg&#8221; +<br />　crlf +<br />　crlf +<br />　file.getAsBinary() +<br />　crlf +<br />　&#8221;&#8211;&#8221; +<br />　boundary +<br />　crlf +<br />　&#8221;Content-Disposition: form-data; &#8221; +<br />　&#8221;name=\&#8221;hostid\&#8221;" +<br />　crlf +<br />　crlf +<br />　userId +<br />　crlf +<br />　&#8221;&#8211;&#8221; +<br />　boundary +<br />　crlf +<br />　&#8221;Content-Disposition: form-data; &#8221; +<br />　&#8221;name=\&#8221;requestToken\&#8221;" +<br />　crlf +<br />　crlf +<br />　t +<br />　crlf +<br />　&#8221;&#8211;&#8221; +<br />　boundary +<br />　&#8217;&#8211;&#8217;;<br />}</p><p style="margin-top: 15px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; list-style-type: none; ">xhr.send(data);</p></div><p style="margin-top: 15px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; list-style-type: none; font-family: Arial, Helvetica, sans-serif, 瀹嬩綋; line-height: 24px; background-color: #fcf1f5; ">首先表单数据headers头信息需要以下两项：</p><ul style="margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 20px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; list-style-type: none; list-style-position: initial; list-style-image: initial; font-family: Arial, Helvetica, sans-serif, 瀹嬩綋; line-height: 24px; background-color: #fcf1f5; "><li style="margin-top: 0px; margin-right: auto; margin-bottom: 0px; margin-left: auto; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 20px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; list-style-type: none; list-style-position: initial; list-style-image: initial; background-image: url(http://www.kuqin.com/new/images/wz_d.png); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: no-repeat no-repeat; ">Content-Type ： 设置其为multipart/form-data来模拟表单数据</li><li style="margin-top: 0px; margin-right: auto; margin-bottom: 0px; margin-left: auto; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 20px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; list-style-type: none; list-style-position: initial; list-style-image: initial; background-image: url(http://www.kuqin.com/new/images/wz_d.png); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: initial initial; background-repeat: no-repeat no-repeat; ">boundary ： 表单数据中的分隔符，用于分隔不同的文件或表单项，这是服务器端设置的格式。</li></ul><p style="margin-top: 15px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; list-style-type: none; font-family: Arial, Helvetica, sans-serif, 瀹嬩綋; line-height: 24px; background-color: #fcf1f5; ">发送时的post数据类似这样：</p><div style="font-family: Arial, Helvetica, sans-serif, 瀹嬩綋; line-height: 24px; background-color: #aaccf7; border-bottom-color: #111111; border-bottom-width: 1px; border-bottom-style: dashed; border-left-color: #111111; border-left-width: 1px; border-left-style: dashed; padding-bottom: 10px; padding-left: 10px; padding-right: 10px; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; color: #0d2742; border-top-color: #111111; border-top-width: 1px; border-top-style: dashed; border-right-color: #111111; border-right-width: 1px; border-right-style: dashed; padding-top: 10px; ">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-1323611763556<br />Content-Disposition: form-data; name=&#8221;file&#8221;; filename=&#8221;4.jpg&#8221;<br />Content-Type: image/jpeg<p style="margin-top: 15px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; list-style-type: none; ">&nbsp;</p><p style="margin-top: 15px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; list-style-type: none; ">&#255;&#216;&#255;&#224;�JFIF�&#8230;这里是文件二进制流&#8230;~i&#250;o&#238;&#173;5P%-v&#227;&#238;H&#252; 4QHg&#255;&#217;<br />&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-1323611763556<br />Content-Disposition: form-data; name=&#8221;hostid&#8221;</p><p style="margin-top: 15px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; list-style-type: none; ">229421603<br />&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;1323612996486</p><p style="margin-top: 15px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; list-style-type: none; ">Content-Disposition: form-data; name=&#8221;requestToken&#8221;</p><p style="margin-top: 15px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; list-style-type: none; ">369009193<br />&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-1323611763556&#8211;</p></div><p style="margin-top: 15px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; list-style-type: none; font-family: Arial, Helvetica, sans-serif, 瀹嬩綋; line-height: 24px; background-color: #fcf1f5; ">好了，现在文件上传成功后你就可以按照平常AJAX的操作来进行后续处理了。</p><p style="margin-top: 15px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; list-style-type: none; font-family: Arial, Helvetica, sans-serif, 瀹嬩綋; line-height: 24px; background-color: #fcf1f5; ">最后，再来总结一下拖拽上传的技术要点：</p><ol style="font-family: Arial, Helvetica, sans-serif, 瀹嬩綋; line-height: 24px; background-color: #fcf1f5; "><li style="margin-top: 0px; margin-right: auto; margin-bottom: 0px; margin-left: auto; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; list-style-type: decimal; list-style-position: initial; list-style-image: initial; "><strong>监听拖拽</strong>：监听页面元素的拖拽事件，包括：<strong>dragenter、dragover、dragleave和drop</strong>，一定要将dragover的默认事件取消掉，不然无法触发drop事件。如需拖拽页面里的元素，需要给其添加属性draggable=&#8221;true&#8221;；</li><li style="margin-top: 0px; margin-right: auto; margin-bottom: 0px; margin-left: auto; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; list-style-type: decimal; list-style-position: initial; list-style-image: initial; "><strong>获取拖拽文件</strong>：在drop事件触发后通过<strong>e.dataTransfer.files</strong>获取拖拽文件列表，<strong>.length</strong>属性获取文件数量，.type属性获取文件类型。</li><li style="margin-top: 0px; margin-right: auto; margin-bottom: 0px; margin-left: auto; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; list-style-type: decimal; list-style-position: initial; list-style-image: initial; "><strong>读取图片数据并添加预览图</strong>：实例化<strong>FileReader</strong>对象，通过其<strong>readAsDataURL(file)</strong>方法获取文件二进制流，并监听其<strong>onload事件</strong>，将<strong>e.result</strong>赋值给img的src属性，最后将图片append到DOM中。</li><li style="margin-top: 0px; margin-right: auto; margin-bottom: 0px; margin-left: auto; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; list-style-type: decimal; list-style-position: initial; list-style-image: initial; "><strong>发送图片数据</strong>：使用<strong>file.getAsBinary</strong>&nbsp;和&nbsp;<strong>FormDat</strong>a分别模拟表单数据AJAX提交文件流。</li></ol><p style="margin-top: 15px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; list-style-type: none; font-family: Arial, Helvetica, sans-serif, 瀹嬩綋; line-height: 24px; background-color: #fcf1f5; ">OK,拖拽上传就讲到这里，欢迎大家一起探讨。</p><img src ="http://www.blogjava.net/xiaomage234/aggbug/372202.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/xiaomage234/" target="_blank">小马歌</a> 2012-03-19 16:35 <a href="http://www.blogjava.net/xiaomage234/archive/2012/03/19/372202.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>HTML5 Geolocation API</title><link>http://www.blogjava.net/xiaomage234/archive/2012/03/16/372045.html</link><dc:creator>小马歌</dc:creator><author>小马歌</author><pubDate>Fri, 16 Mar 2012 07:25:00 GMT</pubDate><guid>http://www.blogjava.net/xiaomage234/archive/2012/03/16/372045.html</guid><wfw:comment>http://www.blogjava.net/xiaomage234/comments/372045.html</wfw:comment><comments>http://www.blogjava.net/xiaomage234/archive/2012/03/16/372045.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/xiaomage234/comments/commentRss/372045.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/xiaomage234/services/trackbacks/372045.html</trackback:ping><description><![CDATA[<div><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 8px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 23px; color: #333333; font-family: tahoma, arial, ����, &#930;���ź�; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #ffffff; ">HTML5提供了一组API用来获取用户的地理位置，如果浏览器支持且设备具有定位功能，就能够直接使用这组API来获取当前位置信息。</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 8px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 23px; color: #333333; font-family: tahoma, arial, ����, &#930;���ź�; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #ffffff; ">该API是navigator对象的一个属性 &#8211; Geolocation。目前除了ie内核浏览器外，其他浏览器的最新版本基本都支持Geolocation。同时，移动设备IOS 3.0+ 和 Android 2.0+ 系统也支持它，现在很多移动设备的应用加入了地理定位的元素。</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 8px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 23px; color: #333333; font-family: tahoma, arial, ����, &#930;���ź�; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #ffffff; ">那么我们接下来看如何使用Geolocation API：</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 8px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 23px; color: #333333; font-family: tahoma, arial, ����, &#930;���ź�; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #ffffff; "><strong>一、检查浏览器是否支持Geolocation</strong><br /><code style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ebebeb; background-position: initial initial; background-repeat: initial initial; "><br />var hasGeolocation = !!(navigator.geolocation);<br />if(hasGeolocation){<br />alert(&#8220;浏览器支持hasGeolocation&#8221;);<br />}<br /></code></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 8px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 23px; color: #333333; font-family: tahoma, arial, ����, &#930;���ź�; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #ffffff; "><strong>二、navigator.geolocation 的方法:</strong></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 8px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 23px; color: #333333; font-family: tahoma, arial, ����, &#930;���ź�; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #ffffff; ">* navigator.geolocation有三个方法，分别是getCurrentPosition()、watchPosition()和clearWatch()</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 8px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 23px; color: #333333; font-family: tahoma, arial, ����, &#930;���ź�; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #ffffff; "><strong>getCurrentPosition()方法</strong></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 8px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 23px; color: #333333; font-family: tahoma, arial, ����, &#930;���ź�; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #ffffff; ">* getCurrentPosition()方法检索用户的当前位置，但只检索一次。当该方法被脚本调用时，方法以异步的方式来尝试获取宿主设备的当前位置。</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 8px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 23px; color: #333333; font-family: tahoma, arial, ����, &#930;���ź�; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #ffffff; ">* 该方法最多可以有三个参数：</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 8px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 23px; color: #333333; font-family: tahoma, arial, ����, &#930;���ź�; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #ffffff; "><strong>geolocationSuccess</strong>：带回当前位置的回调（callback）（必需的）<br /><strong>geolocationError</strong>：有错误发生时使用的回调（可选的）<br /><strong>geolocationOptions</strong>：地理位置选项（可选的）</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 8px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 23px; color: #333333; font-family: tahoma, arial, ����, &#930;���ź�; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #ffffff; ">调用如下所示：</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 8px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 23px; color: #333333; font-family: tahoma, arial, ����, &#930;���ź�; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #ffffff; "><code style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ebebeb; background-position: initial initial; background-repeat: initial initial; "><br />navigator.geolocation.getCurrentPosition(geolocationSuccess, geolocationError, geolocationOptions);<br /></code></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 8px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 23px; color: #333333; font-family: tahoma, arial, ����, &#930;���ź�; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #ffffff; "><strong>watchPosition()方法</strong></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 8px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 23px; color: #333333; font-family: tahoma, arial, ����, &#930;���ź�; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #ffffff; ">* watchPosition()方法定期轮询用户的位置，查看用户的位置是否发生改变。其最多可带三个参数。</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 8px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 23px; color: #333333; font-family: tahoma, arial, ����, &#930;���ź�; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #ffffff; ">调用如下所示：</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 8px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 23px; color: #333333; font-family: tahoma, arial, ����, &#930;���ź�; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #ffffff; "><code style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ebebeb; background-position: initial initial; background-repeat: initial initial; "><br />var watchPositionHandler = navigator.geolocation.watchPosition(geolocationSuccess, geolocationError, geolocationOptions);<br /></code></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 8px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 23px; color: #333333; font-family: tahoma, arial, ����, &#930;���ź�; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #ffffff; "><strong>clearWatch()方法</strong></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 8px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 23px; color: #333333; font-family: tahoma, arial, ����, &#930;���ź�; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #ffffff; ">* clearWatch()方法终止正在进行的watchPosition()，该方法只能带一个参数。在调用时，其找到之前已经开始了的watchID参数并立即停止它。</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 8px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 23px; color: #333333; font-family: tahoma, arial, ����, &#930;���ź�; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #ffffff; ">调用如下所示：</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 8px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 23px; color: #333333; font-family: tahoma, arial, ����, &#930;���ź�; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #ffffff; "><code style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ebebeb; background-position: initial initial; background-repeat: initial initial; "><br />navigator.geolocation.clearWatch(watchID);<br /></code></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 8px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 23px; color: #333333; font-family: tahoma, arial, ����, &#930;���ź�; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #ffffff; "><strong>三、navigator.geolocation返回一个Position对象:</strong></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 8px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 23px; color: #333333; font-family: tahoma, arial, ����, &#930;���ź�; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #ffffff; ">* Position对象有两个属性：timestamp和coords。timestamp属性表示地理位置数据的创建时间，coords属性又包含七个属性：</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 8px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 23px; color: #333333; font-family: tahoma, arial, ����, &#930;���ź�; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #ffffff; "><strong>coords.latitude</strong>：估计纬度<br /><strong>coords.longitude</strong>：估计经度<br /><strong>coords.altitude</strong>：估计高度<br /><strong>coords.accuracy</strong>：所提供的以米为单位的经度和纬度估计的精确度<br /><strong>coords.altitudeAccuracy</strong>：所提供的以米为单位的高度估计的精确度<br /><strong>coords.heading</strong>： 宿主设备当前移动的角度方向，相对于正北方向顺时针计算<br /><strong>coords.speed</strong>：以米每秒为单位的设备的当前对地速度</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 8px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 23px; color: #333333; font-family: tahoma, arial, ����, &#930;���ź�; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #ffffff; ">* 注意altitude, altitudeAccuracy, heading, speed不一定被浏览器支持，所以大家最好看一下官方规范的描述，多一些了解。</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 8px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 23px; color: #333333; font-family: tahoma, arial, ����, &#930;���ź�; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #ffffff; "><strong>四、注意事项</strong></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 8px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 23px; color: #333333; font-family: tahoma, arial, ����, &#930;���ź�; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #ffffff; ">* Geolocation App是不能直接访问设备的，只能通过请求浏览器来访问设备；<br />* Geolocation涉及到用户隐私，在获取 Geolocation 的时候，需要先征求用户的意思。<br />* Geolocation目前没有比较好的前端兼容解决方案，但是在移动设备 iOS 和 Android上，我们可以大胆尝试使用。</p></div><img src ="http://www.blogjava.net/xiaomage234/aggbug/372045.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/xiaomage234/" target="_blank">小马歌</a> 2012-03-16 15:25 <a href="http://www.blogjava.net/xiaomage234/archive/2012/03/16/372045.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>学习html5的history API</title><link>http://www.blogjava.net/xiaomage234/archive/2012/03/16/372044.html</link><dc:creator>小马歌</dc:creator><author>小马歌</author><pubDate>Fri, 16 Mar 2012 07:24:00 GMT</pubDate><guid>http://www.blogjava.net/xiaomage234/archive/2012/03/16/372044.html</guid><wfw:comment>http://www.blogjava.net/xiaomage234/comments/372044.html</wfw:comment><comments>http://www.blogjava.net/xiaomage234/archive/2012/03/16/372044.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/xiaomage234/comments/commentRss/372044.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/xiaomage234/services/trackbacks/372044.html</trackback:ping><description><![CDATA[<div><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 8px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 23px; color: #333333; font-family: tahoma, arial, ����, &#930;���ź�; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #ffffff; ">不得不佩服下谷歌Chrome团队，利用HTML5和CSS3实现了一本相当漂亮的在线电子书：《关于浏览器和互联网20件事》。</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 8px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 23px; color: #333333; font-family: tahoma, arial, ����, &#930;���ź�; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #ffffff; ">访问地址：<a title="关于浏览器和互联网20件事" href="http://www.20thingsilearned.com/" style="color: #0066cc; text-decoration: none; ">http://www.20thingsilearned.com</a></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 8px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 23px; color: #333333; font-family: tahoma, arial, ����, &#930;���ź�; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #ffffff; ">话说这本电子书已经出来很久了，不过今天来看依然觉得相当的赞。我们无需刷新页面，就可以来回切换电子书页面，这正是OPOA（One Page One Application）的完美体现。</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 8px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 23px; color: #333333; font-family: tahoma, arial, ����, &#930;���ź�; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #ffffff; ">现在正在学习关于history API这方面的东西，所以特别感兴趣的是他们如何使用window.history.pushState()和window.history.replaceState()来做页面之间的不刷新切换。</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 8px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 23px; color: #333333; font-family: tahoma, arial, ����, &#930;���ź�; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #ffffff; ">今天查阅了一些资料，基本上对history API有了一个基本了解。</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 8px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 23px; color: #333333; font-family: tahoma, arial, ����, &#930;���ź�; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #ffffff; ">首先要说的就是history是个全局，即window.history。看到这个变量名你一定很熟悉，因为经常可以看到用window.history.back()或者window.history.go(-1)来返回上一页的JavaScript代码。</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 8px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 23px; color: #333333; font-family: tahoma, arial, ����, &#930;���ź�; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #ffffff; ">所以history并不是什么新东西，在HTML4的时代，我们可以使用它的这几个属性和方法：</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 8px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 23px; color: #333333; font-family: tahoma, arial, ����, &#930;���ź�; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #ffffff; ">length：历史堆栈中的记录数。</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 8px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 23px; color: #333333; font-family: tahoma, arial, ����, &#930;���ź�; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #ffffff; ">back()：返回上一页。</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 8px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 23px; color: #333333; font-family: tahoma, arial, ����, &#930;���ź�; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #ffffff; ">forward()：前进到下一页。</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 8px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 23px; color: #333333; font-family: tahoma, arial, ����, &#930;���ź�; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #ffffff; ">go([delta])：delta是个数字，如果不写或为0，则刷新本页；如果为正数，则前进到相应数目的页面；若为负数，则后退到相应数目的页面。</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 8px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 23px; color: #333333; font-family: tahoma, arial, ����, &#930;���ź�; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #ffffff; ">现在，HTML5为其又添加了以下2个方法：</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 8px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 23px; color: #333333; font-family: tahoma, arial, ����, &#930;���ź�; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #ffffff; ">pushState(data, title [, url])：往历史堆栈的顶部添加一条记录。data为一个对象或null，它会在触发window的popstate事件(window.onpopstate)时，作为参数的state属性传递过去；title为页面的标题，但当前所有浏览器都忽略这个参数；url为页面的URL，不写则为当前页。</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 8px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 23px; color: #333333; font-family: tahoma, arial, ����, &#930;���ź�; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #ffffff; ">replaceState(data, title [, url])：更改当前页面的历史记录。参数同上。这种更改并不会去访问该URL。不过目前只有Safari 5.0+、Chrome 8.0+、Firefox 4.0+和iOS 4.2.1+支持。如果想兼容老浏览器的话，可以试试<a href="https://github.com/balupton/history.js" style="color: #0066cc; text-decoration: none; ">History.js</a>，而且它还修正了一些bug。</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 8px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 23px; color: #333333; font-family: tahoma, arial, ����, &#930;���ź�; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #ffffff; ">当然，在移动平台上，我们可以大胆尝试html5的history API。ios3.0+ 和Android2.0+ 平台的内置浏览器对history都比较完美了，利用它我们可以web app更趋向与native app。</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 8px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 23px; color: #333333; font-family: tahoma, arial, ����, &#930;���ź�; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #ffffff; ">下面，推荐几篇文章：</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 8px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 23px; color: #333333; font-family: tahoma, arial, ����, &#930;���ź�; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #ffffff; ">.<a href="https://developer.mozilla.org/en/DOM/Manipulating_the_browser_history" style="color: #0066cc; text-decoration: none; ">Manipulating the browser history</a></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 8px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 23px; color: #333333; font-family: tahoma, arial, ����, &#930;���ź�; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #ffffff; ">.<a href="http://dev.w3.org/html5/spec-author-view/history.html" style="color: #0066cc; text-decoration: none; ">Session history and navigation</a></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 8px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 23px; color: #333333; font-family: tahoma, arial, ����, &#930;���ź�; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: #ffffff; ">.<a href="http://diveintohtml5.org/history.html" style="color: #0066cc; text-decoration: none; ">Manipulating History for Fun &amp; Profit</a></p></div><img src ="http://www.blogjava.net/xiaomage234/aggbug/372044.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/xiaomage234/" target="_blank">小马歌</a> 2012-03-16 15:24 <a href="http://www.blogjava.net/xiaomage234/archive/2012/03/16/372044.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>HTML5 修改浏览器url而不刷新页面【转】</title><link>http://www.blogjava.net/xiaomage234/archive/2012/03/16/372043.html</link><dc:creator>小马歌</dc:creator><author>小马歌</author><pubDate>Fri, 16 Mar 2012 07:18:00 GMT</pubDate><guid>http://www.blogjava.net/xiaomage234/archive/2012/03/16/372043.html</guid><wfw:comment>http://www.blogjava.net/xiaomage234/comments/372043.html</wfw:comment><comments>http://www.blogjava.net/xiaomage234/archive/2012/03/16/372043.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/xiaomage234/comments/commentRss/372043.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/xiaomage234/services/trackbacks/372043.html</trackback:ping><description><![CDATA[<div><br />嘛，起因是黑子大叔在微博上的一条@信息，找起了这个的实现，看了一圈google的中文信息内似乎还没有怎么提到这个的内容，就发表上来。<br />详细效果就是类似于用Firefox4+/Chrome 5+/Safari 5+/Opera 11.5+登录新浪微博后看到的个人时间轴，在翻页时可以观察到这个效果，地址栏URL变动，但是页面没有刷新，用firebug观察也观察不到刷新整个页面，只有ajax请求的翻页数据。从先前的理解来说，URL的修改必然引起（请注意我不是在说通过锚点修改）浏览器重载页面，但利用HTML5新加入的history.pushState();和history.replaceState();可以完全自己维护一个历史记录列表绕开历史记录完全由浏览器控制的机制，从而实现比锚点更加完美的一种页内更新的体验。<br />代码方面很简单，只要在需要修改url的地方插入一行：<br />window.history.pushState({"html":response.html,"pageTitle":response.pageTitle}, 'title', urlPath);<br />//三个参数，分别为：状态对象，标题（目前被浏览器忽略），地址<br />即可在历史记录里面产生一个新的历史记录（另一个replaceState方法参数完全相同，只是替代掉当前的状态）。<br />在体验上，非常接近于使用锚点（window.location = &#8220;#foo&#8221;;），但是mozilla的文档提出了以下三点好处：<br />新的URL可以是和原始页面URL同域下的任何URL，如果用锚点，只能更新#后面的部分<br />仅在需要时更新URL，锚点的历史记录在相同时不会创建（即当前已经是&#8221;#foo&#8221;的情况下，如果再将当前页面锚点设置为&#8221;#foo&#8221;，不会产生新的历史记录）<br />可以记录下任意类型的数据，使用锚点的话将要自己维护一份历史数据列表或者把数据转码到一个字符串里<br />（翻译&amp;描述的有点别扭，见笑了，不过其实应该自己也能体会到这些好处才是）<br />我自己实现的一个例子：<br />http://vifix.cn/atelier/demos/html5-update-browser-url-without-reloading-page<br />代码：<br />&lt;?php<br />if(!isset($_REQUEST['page'])){<br />&nbsp;&nbsp; &nbsp;$page = 1;<br />}<br />else{<br />&nbsp;&nbsp; &nbsp;$page = intval($_REQUEST['page']);<br />}<br />&nbsp;<br />if(isset($_REQUEST['ajaxload'])){<br />&nbsp;&nbsp; &nbsp;echo "第{$page}页的内容";<br />&nbsp;&nbsp; &nbsp;die;<br />}<br />?&gt;<br />&lt;!DOCTYPE html&gt;<br />&lt;html&gt;<br />&lt;head&gt;<br />&lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /&gt;<br />&lt;title&gt;HTML5 修改浏览器url而不刷新页面&lt;/title&gt;<br />&lt;script type="text/javascript"&gt;<br />var domLoaded = function(){<br />&nbsp;&nbsp; &nbsp;if(ua != null &amp;&amp; ua[1] &lt; 10){<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;alert('您的浏览器不支持');<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;return ;<br />&nbsp;&nbsp; &nbsp;}<br />&nbsp;<br />&nbsp;&nbsp; &nbsp;if(location.href.indexOf("?") &gt; -1){<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;var urlparts = location.href.match(/(.+?)\?.+/i);<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;var urlbase = urlparts[1];<br />&nbsp;&nbsp; &nbsp;}<br />&nbsp;&nbsp; &nbsp;else{<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;var urlbase = location.href;<br />&nbsp;&nbsp; &nbsp;}<br />&nbsp;&nbsp; &nbsp;var page = &lt;?php echo $page;?&gt;;<br />&nbsp;&nbsp; &nbsp;var ua = window.navigator.userAgent.match(/msie (\d\.\d)/i);<br />&nbsp;&nbsp; &nbsp;var content = document.getElementById("content");<br />&nbsp;&nbsp; &nbsp;var loading = document.getElementById("loading");<br />&nbsp;<br />&nbsp;&nbsp; &nbsp;window.history.replaceState(<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;{<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;content:content.innerHTML,<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;page:page<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;},<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;page,<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;urlbase + (page &gt; 1 ? '?page=' + page : '' )<br />&nbsp;&nbsp; &nbsp;);<br />&nbsp;<br />&nbsp;&nbsp; &nbsp;var ajax = new XMLHttpRequest();<br />&nbsp;&nbsp; &nbsp;var ajaxCallback = function(){<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if(ajax.readyState == 4){<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;loading.style.display = 'none';<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;content.innerHTML = ajax.responseText;<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;window.history.pushState(<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;{<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;content:content.innerHTML,<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;page:page<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;},<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;page,<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;urlbase + "?page=" + page<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;);<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;next.href = urlbase + "?page=" + (page + 1);<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}<br />&nbsp;&nbsp; &nbsp;};<br />&nbsp;<br />&nbsp;&nbsp; &nbsp;var next = document.getElementById('next');<br />&nbsp;&nbsp; &nbsp;var nextClickEvent = function(event){<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if(loading.style.display != 'block'){<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;loading.style.display = 'block';<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;page++;<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;ajax.open('GET', urlbase + '?page=' + page + '&amp;ajaxload=on', true);<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;ajax.onreadystatechange = ajaxCallback;<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;ajax.send('');<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;event.preventDefault();<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}<br />&nbsp;&nbsp; &nbsp;};<br />&nbsp;&nbsp; &nbsp;next.addEventListener('click', nextClickEvent, false);<br />&nbsp;<br />&nbsp;&nbsp; &nbsp;var popstate = function(){<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;content.innerHTML = history.state.content;<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;page = history.state.page;<br />&nbsp;&nbsp; &nbsp;};<br />&nbsp;&nbsp; &nbsp;window.addEventListener('popstate', popstate, false);<br />};<br />&nbsp;<br />try{<br />&nbsp;&nbsp; &nbsp;window.addEventListener('DOMContentLoaded', domLoaded, false);<br />}<br />catch(e){<br />&nbsp;&nbsp; &nbsp;alert('您的浏览器不支持');&nbsp;&nbsp; &nbsp;<br />}<br />&lt;/script&gt;<br />&lt;/head&gt;<br />&lt;body&gt;<br />&nbsp;&nbsp; &nbsp;&lt;p id="content"&gt;<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&lt;?php echo "第{$page}页的内容";?&gt;<br />&nbsp;&nbsp; &nbsp;&lt;/p&gt;<br />&nbsp;&nbsp; &nbsp;&lt;p&gt;<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&lt;a id="next" href="?page=&lt;?php echo $page+1;?&gt;"&gt;下一页&lt;/a&gt;<br />&nbsp;&nbsp; &nbsp;&lt;/p&gt;<br />&nbsp;&nbsp; &nbsp;&lt;div id="loading" style="display:none;"&gt;<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;加载中<br />&nbsp;&nbsp; &nbsp;&lt;/div&gt;<br />&lt;/body&gt;<br />&lt;/html&gt;<br />mozilla的文档<br />https://developer.mozilla.org/en/DOM/Manipulating_the_browser_history<br />stackoverflow上的相关问题：<br />http://stackoverflow.com/questions/3338642/updating-address-bar-with-new-url-without-hash-or-reloading-the-page<br />http://stackoverflow.com/questions/824349/modify-the-url-without-reloading-the-page</div><img src ="http://www.blogjava.net/xiaomage234/aggbug/372043.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/xiaomage234/" target="_blank">小马歌</a> 2012-03-16 15:18 <a href="http://www.blogjava.net/xiaomage234/archive/2012/03/16/372043.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>提升用户体验：HTML5 拖放文件上传【转】</title><link>http://www.blogjava.net/xiaomage234/archive/2012/03/08/371525.html</link><dc:creator>小马歌</dc:creator><author>小马歌</author><pubDate>Thu, 08 Mar 2012 05:57:00 GMT</pubDate><guid>http://www.blogjava.net/xiaomage234/archive/2012/03/08/371525.html</guid><wfw:comment>http://www.blogjava.net/xiaomage234/comments/371525.html</wfw:comment><comments>http://www.blogjava.net/xiaomage234/archive/2012/03/08/371525.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/xiaomage234/comments/commentRss/371525.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/xiaomage234/services/trackbacks/371525.html</trackback:ping><description><![CDATA[<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Georgia, 宋体, Arial, sans-serif; background-color: #f7eecf; ">话说，还是有不少项目里提供让用户上传东西的。小到一个 wordpress 博客，大到一个文件存储网站。为了更好的用户体验。来学习两个新知识吧。HTML5 文件访问（File Access: FileReader）和拖放（Drag and Drop）。或许下个项目就能用上了。</p><h3>一、起因</h3><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Georgia, 宋体, Arial, sans-serif; background-color: #f7eecf; "><img src="http://min.us/smedia/root/logo_hover_small.png" alt="minus" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; " /></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Georgia, 宋体, Arial, sans-serif; background-color: #f7eecf; ">今天看到 twitter 上有人在分享 Min.us 这个网站。说是只要把图片进去，就可以分享。是的，它确实是这样。体验了一翻，无论从界面，还操作的方便性上说，这体验还真是很赞的。</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Georgia, 宋体, Arial, sans-serif; background-color: #f7eecf; "></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Georgia, 宋体, Arial, sans-serif; background-color: #f7eecf; ">不过，我更在意的是，他用了什么样的技术。想着今晚回来瞄下代码。这下，汗的事来了。这页面看起来不像前端写的啊。乱七八糟的。真是看不下去了。不过，为了更好的用户体验，看吧。从页面的 HTML5 标签猜测到可能用到 HTML5 的某些 API，再查一下 JS 发现了这两行：</p><pre style="margin-top: 0px; margin-bottom: 15px; padding-top: 15px; padding-right: 15px; padding-bottom: 15px; padding-left: 15px; width: 490px; overflow-x: auto; overflow-y: auto; font-family: 'Courier New', Courier, monospace; font-size: 12px; line-height: 1.1; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-top-color: #b3b3b3; border-right-color: #b3b3b3; border-bottom-color: #b3b3b3; border-image: initial; border-left-width: 5px; border-left-style: solid; border-left-color: #dddddd; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f7eecf; ">function isValidBrowser() {   var browser = BrowserDetect.browser;   var version = BrowserDetect.version;   var OS = BrowserDetect.OS;   //alert(browser+','+version+','+OS);   return (     (browser == 'Chrome' &amp;&amp; version &gt;= 6) ||     (browser == 'Firefox' &amp;&amp; version &gt;= 3.6) || 	(browser == 'Safari' &amp;&amp; version &gt;= 5.0 &amp;&amp; OS == 'Mac') ||     ("FileReader" in self &amp;&amp; "ondrag" in document)   ); } </pre><h3>二、DEMO</h3><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 15px; padding-right: 15px; padding-bottom: 15px; padding-left: 15px; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f7eecf; border-top-left-radius: 5px; border-top-right-radius: 5px; border-bottom-right-radius: 5px; border-bottom-left-radius: 5px; font-family: Georgia; color: #888888; -webkit-transition-property: border-color; -webkit-transition-duration: 0.5s; -webkit-transition-timing-function: ease-in; -webkit-transition-delay: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #ffffff; border-right-color: #ffffff; border-bottom-color: #ffffff; border-left-color: #ffffff; border-image: initial; ">先来个预览吧，你可以先玩玩，再接着往下面看：<a href="http://sofish.de/file/demo/drag-and-drop-files.html" style="text-decoration: none; color: #cc3300; border-bottom-width: 1px; border-bottom-style: dotted; border-bottom-color: #a3a3a3; ">HTML5 文件拖放上传</a></p><h3>三、如何实现</h3><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Georgia, 宋体, Arial, sans-serif; background-color: #f7eecf; ">好吧，确定是使用HTML5。我们来看一下这种技术是怎么实现的吧。嗯，再回看上面的代码，还有我提了这么多次，其实，它就用到两个技术：</p><ol style="margin-top: 0px; margin-right: 41px; margin-bottom: 15px; margin-left: 28px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; font-family: Georgia, 宋体, Arial, sans-serif; background-color: #f7eecf; "><li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: decimal; list-style-position: initial; list-style-image: initial; ">FileReader，HTML5 File API</li><li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: decimal; list-style-position: initial; list-style-image: initial; ">Drag and Drop，似乎IE从 5.5 就支持了，都不敢说她是 HTML5 了</li></ol><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Georgia, 宋体, Arial, sans-serif; background-color: #f7eecf; ">这里有两篇比较详细的文章，看（等看完我讲的，你再去看吧）：</p><ol style="margin-top: 0px; margin-right: 41px; margin-bottom: 15px; margin-left: 28px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; font-family: Georgia, 宋体, Arial, sans-serif; background-color: #f7eecf; "><li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: decimal; list-style-position: initial; list-style-image: initial; "><a href="http://www.html5rocks.com/tutorials/dnd/basics/" style="text-decoration: none; color: #cc3300; border-bottom-width: 1px; border-bottom-style: dotted; border-bottom-color: #a3a3a3; ">Native HTML5 Drag and Drop</a></li><li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: decimal; list-style-position: initial; list-style-image: initial; "><a href="http://www.html5rocks.com/tutorials/file/dndfiles/" style="text-decoration: none; color: #cc3300; border-bottom-width: 1px; border-bottom-style: dotted; border-bottom-color: #a3a3a3; ">Reading local files in JavaScript</a></li></ol><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Georgia, 宋体, Arial, sans-serif; background-color: #f7eecf; ">现在 1:10 am 了，同学。明天还要上班。而具体讲来，还是需要很多时间滴。我们就简单一点。说些应该注意的吧。具体的实现，你看我 DEMO 的代码吧，和上面的文章吧。</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Georgia, 宋体, Arial, sans-serif; background-color: #f7eecf; "><strong>一、 浏览器检测 &amp; 支持</strong></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Georgia, 宋体, Arial, sans-serif; background-color: #f7eecf; ">支持的浏览器并不多，我测试的是 Filefox 和 Chrome， winSafari 5.0.2 没通过。IE8 以下就更不用说了，当然，Opera 也没有支持。</p><pre style="margin-top: 0px; margin-bottom: 15px; padding-top: 15px; padding-right: 15px; padding-bottom: 15px; padding-left: 15px; width: 490px; overflow-x: auto; overflow-y: auto; font-family: 'Courier New', Courier, monospace; font-size: 12px; line-height: 1.1; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-top-color: #b3b3b3; border-right-color: #b3b3b3; border-bottom-color: #b3b3b3; border-image: initial; border-left-width: 5px; border-left-style: solid; border-left-color: #dddddd; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f7eecf; ">if (window.FileReader) { 	// 做事的 } else { 	alert('你的浏览器不支持啊，同学') } </pre><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Georgia, 宋体, Arial, sans-serif; background-color: #f7eecf; ">从 Minus 的代码中可以看出，支持的有：</p><ol style="margin-top: 0px; margin-right: 41px; margin-bottom: 15px; margin-left: 28px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; font-family: Georgia, 宋体, Arial, sans-serif; background-color: #f7eecf; "><li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: decimal; list-style-position: initial; list-style-image: initial; ">Chrome 6+</li><li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: decimal; list-style-position: initial; list-style-image: initial; ">Firefox 3.6+</li><li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: decimal; list-style-position: initial; list-style-image: initial; "><strike>Mac Safari 5.0+</strike></li></ol><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Georgia, 宋体, Arial, sans-serif; background-color: #f7eecf; ">其他的，就是浮云了。不过，这已经足够了，因为我们可以用 hack 来实现。我们这里，就讲可以用的吧。不可以的，就用原来项目中使用的方法吧。</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Georgia, 宋体, Arial, sans-serif; background-color: #f7eecf; "><strong>二、注意事项</strong></p><ol style="margin-top: 0px; margin-right: 41px; margin-bottom: 15px; margin-left: 28px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; font-family: Georgia, 宋体, Arial, sans-serif; background-color: #f7eecf; "><li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: decimal; list-style-position: initial; list-style-image: initial; ">浏览器默认行为<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">默认情况下，你向 Firefox 拖进一张图片，他可能会重定向于新页面。或者拖过一个链接，可能会让页面重定向。我想，你一定不会让你的用户一边上传，一边又打开一个本地文件页面，然后让他再跑回来上传的页面。那就，阻止浏览器默认行为是非常有必要的。</p></li><li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: decimal; list-style-position: initial; list-style-image: initial; ">事件绑定<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">你可能发现了，在 DEMO 当我们把东西拖进容器的时候，容器的边框样式变成虚线。因为我这里绑定了一个事件，当文件进入目标是，添加一个 dragenter 的 CLASSNAME。这里需要注意的事，减少事件的解法，你可以在事件 ondragenter 的时候，添加 CLASSNAME ，而 ondragleave 的时候，删除 CLASSNAME。但绑定在 dragover 上，他就像 mouseover ，在拖动的过程中不断解发，这对于浏览器的负担就很大了。可能会导致一些乱七八糟的，类似于崩溃之类的事。</p></li><li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: decimal; list-style-position: initial; list-style-image: initial; ">dataTransfer 的格式<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">你可能需要用 e.dataTransfer.setData 和 e.dataTransfer.getData 来决定是否上传用户拖放的文件。</p></li><li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: decimal; list-style-position: initial; list-style-image: initial; ">File API 的状态和 result<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">检测状态，以便下一步操作，而 result 则可以实现本地预览的功能，让用户知道自己要上传的东西是什么。</p></li><li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: decimal; list-style-position: initial; list-style-image: initial; ">File API 的读取格式<ul style="margin-top: 0px; margin-right: 41px; margin-bottom: 15px; margin-left: 28px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; "><li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: decimal; list-style-position: initial; list-style-image: initial; "><code style="font-family: 'Courier New', Courier, monospace; font-size: 12px; line-height: 1; ">FileReader.readAsBinaryString(fileBlob)</code>&nbsp;-&nbsp;&nbsp;<code style="font-family: 'Courier New', Courier, monospace; font-size: 12px; line-height: 1; ">result</code>&nbsp;属性会包含一个文件的二进制的格式</li><li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: decimal; list-style-position: initial; list-style-image: initial; "><code style="font-family: 'Courier New', Courier, monospace; font-size: 12px; line-height: 1; ">FileReader.readAsText(fileBlob, opt_encoding)</code>&nbsp;-&nbsp;&nbsp;<code style="font-family: 'Courier New', Courier, monospace; font-size: 12px; line-height: 1; ">result</code>属性将会包含一个文件的文本格式，默认解码参数是 &#8220;utf-8&#8221;。</li><li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: decimal; list-style-position: initial; list-style-image: initial; "><code style="font-family: 'Courier New', Courier, monospace; font-size: 12px; line-height: 1; ">FileReader.readAsDataURL(file)</code>&nbsp;-&nbsp;&nbsp;<code style="font-family: 'Courier New', Courier, monospace; font-size: 12px; line-height: 1; ">result</code>&nbsp;将会包含一个文件的 DataURL 格式（图片通常用这种方式）</li></ul></li></ol><h3>四、具体的应用</h3><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Georgia, 宋体, Arial, sans-serif; background-color: #f7eecf; ">其实我还没有见到国内用上这个技术的网站。刚才瞄了一下 QQ 微博。也没有。对于这些新技术。于我们前端开来，其实挑战并不是会不会使用，而是，如何去使用。</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Georgia, 宋体, Arial, sans-serif; background-color: #f7eecf; ">比如，在支付宝，下次需要改版用户上传身份证认证的时候，或许我会去推动这样的改进。又比如，如果是我在做 QQ 微博，或者任何一个微博，我将会提供一个让用户拖让一张图片就能上传的功能。</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Georgia, 宋体, Arial, sans-serif; background-color: #f7eecf; ">HTML5 能用到的地方太多了。就慢你没想法。因为别人其实并不清楚，连最清楚的你，前端，都不去推动，还能有谁去推动呢？</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Georgia, 宋体, Arial, sans-serif; background-color: #f7eecf; ">好吧。在接下来的项目中，你，或许也可以试试。</p><img src ="http://www.blogjava.net/xiaomage234/aggbug/371525.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/xiaomage234/" target="_blank">小马歌</a> 2012-03-08 13:57 <a href="http://www.blogjava.net/xiaomage234/archive/2012/03/08/371525.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>推荐一些采用html5技术，支持直接拖拽上传的网盘</title><link>http://www.blogjava.net/xiaomage234/archive/2012/03/08/371524.html</link><dc:creator>小马歌</dc:creator><author>小马歌</author><pubDate>Thu, 08 Mar 2012 05:56:00 GMT</pubDate><guid>http://www.blogjava.net/xiaomage234/archive/2012/03/08/371524.html</guid><wfw:comment>http://www.blogjava.net/xiaomage234/comments/371524.html</wfw:comment><comments>http://www.blogjava.net/xiaomage234/archive/2012/03/08/371524.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/xiaomage234/comments/commentRss/371524.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/xiaomage234/services/trackbacks/371524.html</trackback:ping><description><![CDATA[<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #4b4b4b; line-height: 24px; text-align: -webkit-left; background-color: #ffffff; text-indent: 28px; font-family: verdana, arial, helvetica, sans-serif; ">跟着html5手艺的不竭成熟，越来越多的应用采用html5手艺，html5的一项吸惹人的功能之一就是能够从桌面直接拖拽文件就可以上传，很是便利，国外已经有几个网盘采用了这一手艺，这里为巨匠介绍几个，当然使用这一功能需要你的浏览器撑持html5手艺。</p><br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #4b4b4b; font-family: Arial, Helvetica, sans-serif; font-size: 12px; line-height: 24px; text-align: -webkit-left; background-color: #ffffff; " /><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #4b4b4b; line-height: 24px; text-align: -webkit-left; background-color: #ffffff; text-indent: 28px; font-family: verdana, arial, helvetica, sans-serif; ">　　1.Let's Crate</p><br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #4b4b4b; font-family: Arial, Helvetica, sans-serif; font-size: 12px; line-height: 24px; text-align: -webkit-left; background-color: #ffffff; " /><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #4b4b4b; line-height: 24px; text-align: -webkit-left; background-color: #ffffff; text-indent: 28px; font-family: verdana, arial, helvetica, sans-serif; ">　　Let's Crate，采用了较新的手艺，拖曳就能快速上传文件(但需要浏览器的撑持，建议使用谷歌浏览器)的一款国外网盘，简单易用，它不需要注册，打开页面后，直接把要上传的文件拖曳到页面中心的木箱里，完成后，会生成文件分享链接。还有它会提醒你注册一个帐户。若是不想注册，那么复制分享链接，但只能使用30 分钟，相当于的用于姑且分享的，建议注册，注册后可以看到你今朝成立的文件夹数、上传文件总数以及可使用的空间，今朝免费帐户可以使用的容量为 200MB。</p><br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #4b4b4b; font-family: Arial, Helvetica, sans-serif; font-size: 12px; line-height: 24px; text-align: -webkit-left; background-color: #ffffff; " /><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #4b4b4b; line-height: 24px; text-align: -webkit-left; background-color: #ffffff; text-indent: 28px; font-family: verdana, arial, helvetica, sans-serif; ">　　网址：</p><br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #4b4b4b; font-family: Arial, Helvetica, sans-serif; font-size: 12px; line-height: 24px; text-align: -webkit-left; background-color: #ffffff; " /><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #4b4b4b; line-height: 24px; text-align: -webkit-left; background-color: #ffffff; text-indent: 28px; font-family: verdana, arial, helvetica, sans-serif; ">　　http://www.letscrate.com/</p><br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #4b4b4b; font-family: Arial, Helvetica, sans-serif; font-size: 12px; line-height: 24px; text-align: -webkit-left; background-color: #ffffff; " /><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #4b4b4b; line-height: 24px; text-align: -webkit-left; background-color: #ffffff; text-indent: 28px; font-family: verdana, arial, helvetica, sans-serif; ">　　2.Ge.tt</p><br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #4b4b4b; font-family: Arial, Helvetica, sans-serif; font-size: 12px; line-height: 24px; text-align: -webkit-left; background-color: #ffffff; " /><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #4b4b4b; line-height: 24px; text-align: -webkit-left; background-color: #ffffff; text-indent: 28px; font-family: verdana, arial, helvetica, sans-serif; ">　　Ge.tt，一个设计精练清雅文件存储分享网盘，上传速度很快。它最年夜的特点在于上传存储分享极其精练便捷，就跟它精练的域名一样，Ge.tt页面只有一个精明的上传文件的按钮。</p><br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #4b4b4b; font-family: Arial, Helvetica, sans-serif; font-size: 12px; line-height: 24px; text-align: -webkit-left; background-color: #ffffff; " /><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #4b4b4b; line-height: 24px; text-align: -webkit-left; background-color: #ffffff; text-indent: 28px; font-family: verdana, arial, helvetica, sans-serif; ">　　它为你供给无限量的收集空间，免费用户撑持保留文件30天，撑持批量上传，可是是经由过程一路选择当地多个文件上传，不需要你一个一个添加文件，一次最多可以上传30个，上传完成后系统会供给超短分享外链地址，也供给一键分享到Facebook和Twitter，当你的鼠标滑过此链接时可复制该链接与你的伴侣分享。</p><br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #4b4b4b; font-family: Arial, Helvetica, sans-serif; font-size: 12px; line-height: 24px; text-align: -webkit-left; background-color: #ffffff; " /><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #4b4b4b; line-height: 24px; text-align: -webkit-left; background-color: #ffffff; text-indent: 28px; font-family: verdana, arial, helvetica, sans-serif; ">　　此外，您还可以经由过程注册获得额外功能，如对下载次数的实时统计、更长久的文件保留时刻。</p><br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #4b4b4b; font-family: Arial, Helvetica, sans-serif; font-size: 12px; line-height: 24px; text-align: -webkit-left; background-color: #ffffff; " /><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #4b4b4b; line-height: 24px; text-align: -webkit-left; background-color: #ffffff; text-indent: 28px; font-family: verdana, arial, helvetica, sans-serif; ">　　网址：http://www.ge.tt/</p><br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #4b4b4b; font-family: Arial, Helvetica, sans-serif; font-size: 12px; line-height: 24px; text-align: -webkit-left; background-color: #ffffff; " /><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #4b4b4b; line-height: 24px; text-align: -webkit-left; background-color: #ffffff; text-indent: 28px; font-family: verdana, arial, helvetica, sans-serif; ">　　3..Min.us</p><br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #4b4b4b; font-family: Arial, Helvetica, sans-serif; font-size: 12px; line-height: 24px; text-align: -webkit-left; background-color: #ffffff; " /><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #4b4b4b; line-height: 24px; text-align: -webkit-left; background-color: #ffffff; text-indent: 28px; font-family: verdana, arial, helvetica, sans-serif; ">　　Min.us，带给你全新上传体验在线图片存储，浏览，分享和打点工具。页面很是精练，您只需把图片拖拽到Min.us的页面里，图片就能自动上传。若是想成批上传图片，只需用鼠标拔取多张一块拖拽到Min.us即可。要考试考试此项功能，必需你的浏览器是Firefox 3.6+, Chrome, Safari, IE9浏览器。否则，会呈现指定文件上传的上传页面。图片上传后Min.us会自动完成而且生成相册链接，便利您分享给伴侣，有作为编纂用（Edit）链接，有用来分享的（Viewer）链接。在每个图片正下方有一个链接（Link to image）便利你将上传后的图片贴到任何网站和博客中。</p><br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #4b4b4b; font-family: Arial, Helvetica, sans-serif; font-size: 12px; line-height: 24px; text-align: -webkit-left; background-color: #ffffff; " /><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #4b4b4b; line-height: 24px; text-align: -webkit-left; background-color: #ffffff; text-indent: 28px; font-family: verdana, arial, helvetica, sans-serif; ">　　今朝Min.us撑持上传的图片名目有：JPEG, JPG, GIF, PNG, APNG，BMP。撑持单张7MB以下的图片上传，每个相册图片不跨越50张，上传的图片是永远保留的。</p><br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #4b4b4b; font-family: Arial, Helvetica, sans-serif; font-size: 12px; line-height: 24px; text-align: -webkit-left; background-color: #ffffff; " /><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #4b4b4b; line-height: 24px; text-align: -webkit-left; background-color: #ffffff; text-indent: 28px; font-family: verdana, arial, helvetica, sans-serif; ">　　网址：http://min.us/</p><br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #4b4b4b; font-family: Arial, Helvetica, sans-serif; font-size: 12px; line-height: 24px; text-align: -webkit-left; background-color: #ffffff; " /><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #4b4b4b; line-height: 24px; text-align: -webkit-left; background-color: #ffffff; text-indent: 28px; font-family: verdana, arial, helvetica, sans-serif; ">　　4.PicsEngine</p><br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #4b4b4b; font-family: Arial, Helvetica, sans-serif; font-size: 12px; line-height: 24px; text-align: -webkit-left; background-color: #ffffff; " /><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #4b4b4b; line-height: 24px; text-align: -webkit-left; background-color: #ffffff; text-indent: 28px; font-family: verdana, arial, helvetica, sans-serif; ">　　PicsEngine，一款在线图片打点存储软件，近似与桌面版的picasa，你也可以将它算作专注于图片存储的网盘。PicsEngine打点照片很是便利轻易，供给使用标签来智能打点相册。它的整体界面设计很是酷的，供给了无限的存储空间，而且可以从任何处所来进行访谒。</p><br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #4b4b4b; font-family: Arial, Helvetica, sans-serif; font-size: 12px; line-height: 24px; text-align: -webkit-left; background-color: #ffffff; " /><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 15px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: #4b4b4b; line-height: 24px; text-align: -webkit-left; background-color: #ffffff; text-indent: 28px; font-family: verdana, arial, helvetica, sans-serif; ">　　PicsEngine有一个强年夜的很新的功能，就是你可以直接从桌面拖动照片到浏览器进行上传，当然体验这一功能你需要安装较高版本的网页浏览器</p><img src ="http://www.blogjava.net/xiaomage234/aggbug/371524.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/xiaomage234/" target="_blank">小马歌</a> 2012-03-08 13:56 <a href="http://www.blogjava.net/xiaomage234/archive/2012/03/08/371524.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>HTML5文件实现拖拽上传【转】</title><link>http://www.blogjava.net/xiaomage234/archive/2012/03/07/371390.html</link><dc:creator>小马歌</dc:creator><author>小马歌</author><pubDate>Wed, 07 Mar 2012 04:32:00 GMT</pubDate><guid>http://www.blogjava.net/xiaomage234/archive/2012/03/07/371390.html</guid><wfw:comment>http://www.blogjava.net/xiaomage234/comments/371390.html</wfw:comment><comments>http://www.blogjava.net/xiaomage234/archive/2012/03/07/371390.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/xiaomage234/comments/commentRss/371390.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/xiaomage234/services/trackbacks/371390.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 通过HTML的文件API ，Firefox、Chrome等浏览器已经支持从操作系统直接拖拽文件，并上传到服务器。&nbsp;&nbsp; &nbsp; 相对于使用了十多年的HTML表单，这是一个革命性的进步。虽然IE的落后让很多开发者还在观望中，但是Gmail邮箱的附件拖拽功能已经给部分用户带来了极大的方便，而需要大量上传文件的CMS（内容管理系统）也将会从中受益。 &nbsp; &nbsp;&n...&nbsp;&nbsp;<a href='http://www.blogjava.net/xiaomage234/archive/2012/03/07/371390.html'>阅读全文</a><img src ="http://www.blogjava.net/xiaomage234/aggbug/371390.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/xiaomage234/" target="_blank">小马歌</a> 2012-03-07 12:32 <a href="http://www.blogjava.net/xiaomage234/archive/2012/03/07/371390.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[情人节专属]纯js脚本1k大小的3D玫瑰</title><link>http://www.blogjava.net/xiaomage234/archive/2012/02/10/369728.html</link><dc:creator>小马歌</dc:creator><author>小马歌</author><pubDate>Fri, 10 Feb 2012 03:59:00 GMT</pubDate><guid>http://www.blogjava.net/xiaomage234/archive/2012/02/10/369728.html</guid><wfw:comment>http://www.blogjava.net/xiaomage234/comments/369728.html</wfw:comment><comments>http://www.blogjava.net/xiaomage234/archive/2012/02/10/369728.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/xiaomage234/comments/commentRss/369728.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/xiaomage234/services/trackbacks/369728.html</trackback:ping><description><![CDATA[<div><p style="line-height: 25px; text-align: left; font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #f8fafd; "><strong>导语：</strong>前年圣诞节上，西班牙程序员Roman Cortes带来了用纯javascript脚本编写的<a target="_blank" href="http://news.csdn.net/a/20101224/286274.html" style="color: #015fb6; text-decoration: none; ">神奇3D圣诞树</a>，令人印象深刻。2月14日情人节就要来临了，还是Roman Cortes，这次他又带来了用javascript脚本编写的红色玫瑰花。用代码做出的玫瑰花，这才是牛逼程序员送给女友的最好情人节礼物呢！<strong>(提示：在不同浏览器下观看效果、速度会有很大的不同)</strong></p><p style="line-height: 25px; text-align: center; font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #f8fafd; "><iframe width="600px" scrolling="no" height="520px" frameborder="0" noresize="noresize" src="http://sd.csdn.net/a/20120209/311621.html"></iframe><br /><br /><br /><br /><br /><br /><br /></p><p style="line-height: 25px; text-align: left; font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #f8fafd; ">图片是由代码生成，用户可以刷新该页面，重复观看这朵玫瑰的呈现过程。</p><p style="line-height: 25px; text-align: left; font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #f8fafd; "><strong>3D玫瑰花的实现代码如下：</strong></p><p style="line-height: 25px; text-align: left; font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #f8fafd; "></p><table align="center" width="95%" cellspacing="0" cellpadding="6" border="0" style="color: #000000; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 12px; line-height: 18px; text-align: left; background-color: #f8fafd; border-right-color: #cccccc; table-layout: fixed; border-top-color: #cccccc; border-left-color: #cccccc; border-bottom-color: #cccccc; "><tbody><tr><td bgcolor="#fdfddf" style="word-wrap: break-word; "><p style="font-size: 14px; line-height: 25px; ">with(m=Math)C=cos,S=sin,P=pow,R=random;c.width=c.height=f=500;h=-250;function p(a,b,c){if(c&gt;60)return[S(a*7)*(13+5/(.2+P(b*4,4)))-S(b)*50,b*f+50,625+C(a*7)*(13+5/(.2+P(b*4,4)))+b*400,a*1-b/2,a];A=a*2-1;B=b*2-1;if(A*A+B*B&lt;1){if(c&gt;37){n=(j=c&amp;1)?6:4;o=.5/(a+.01)+C(b*125)*3-a*300;w=b*h;return[o*C(n)+w*S(n)+j*610-390,o*S(n)-w*C(n)+550-j*350,1180+C(B+A)*99-j*300,.4-a*.1+P(1-B*B,-h*6)*.15-a*b*.4+C(a+b)/5+P(C((o*(a+1)+(B&gt;0?w:-w))/25),30)*.1*(1-B*B),o/1e3+.7-o*w*3e-6]}if(c&gt;32){c=c*1.16-.15;o=a*45-20;w=b*b*h;z=o*S(c)+w*C(c)+620;return[o*C(c)-w*S(c),28+C(B*.5)*99-b*b*b*60-z/2-h,z,(b*b*.3+P((1-(A*A)),7)*.15+.3)*b,b*.7]}o=A*(2-b)*(80-c*2);w=99-C(A)*120-C(b)*(-h-c*4.9)+C(P(1-b,7))*50+c*2;z=o*S(c)+w*C(c)+700;return[o*C(c)-w*S(c),B*99-C(P(b, 7))*50-c/3-z/1.35+450,z,(1-b/1.2)*.9+a*.1, P((1-b),20)/4+.05]}}setInterval('for(i=0;i&lt;1e4;i++)if(s=p(R(),R(),i%46/.74)){z=s[2];x=~~(s[0]*f/z-h);y=~~(s[1]*f/z-h);if(!m[q=y*f+x]|m[q]&gt;z)m[q]=z,a.fillStyle="rgb("+~(s[3]*h)+","+~(s[4]*h)+","+~(s[3]*s[3]*-80)+")",a.fillRect(x,y,1,1)}',0)</p></td></tr></tbody></table><p style="line-height: 25px; text-align: left; font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #f8fafd; "></p><p style="line-height: 25px; text-align: left; font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #f8fafd; "><strong>当然，感兴趣的人可以了解下面的实现过程与相关理论：</strong></p><p style="line-height: 25px; text-align: left; font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #f8fafd; ">这朵三维代码玫瑰的呈现效果采用了蒙特卡罗方法，创造者对蒙特卡罗方法非常推崇，他表示在功能优化和采样方面，蒙特卡罗方法是&#8220;令人难以置信的强大工具&#8221;。关于蒙特卡罗方法可以参考：<a target="_blank" href="http://en.wikipedia.org/wiki/Monte_carlo_method" style="color: #015fb6; text-decoration: none; ">Monte Carlo method</a>&nbsp;。</p><p style="line-height: 25px; text-align: left; font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #f8fafd; ">具体操作：</p><p style="line-height: 25px; text-align: left; font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #f8fafd; "><strong>外观采样呈现效果绘制</strong></p><p style="line-height: 25px; text-align: left; font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #f8fafd; ">我用了多个不同的形状图来组成这朵代码玫瑰。共使用了31个形状：24个花瓣，4个萼片，2个叶子和1根花茎，其中每一个形状图都用代码进行描绘。</p><p style="line-height: 25px; text-align: left; font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #f8fafd; ">首先，来定义一个采样范围：</p><p style="line-height: 25px; text-align: left; font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #f8fafd; "></p><table align="center" width="95%" cellspacing="0" cellpadding="6" border="0" style="color: #000000; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 12px; line-height: 18px; text-align: left; background-color: #f8fafd; border-right-color: #cccccc; table-layout: fixed; border-top-color: #cccccc; border-left-color: #cccccc; border-bottom-color: #cccccc; "><tbody><tr><td bgcolor="#fdfddf" style="word-wrap: break-word; "><p style="font-size: 14px; line-height: 25px; ">function surface(a, b) { // I'm using a and b as parameters ranging from 0 to 1.</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">return {</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">x: a*50,</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">y: b*50</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">};</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">// this surface will be a square of 50x50 units of size</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">}</p></td></tr></tbody></table><p style="line-height: 25px; text-align: left; font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #f8fafd; "></p><p style="line-height: 25px; text-align: left; font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #f8fafd; ">然后，编写形状描绘代码：</p><p style="line-height: 25px; text-align: left; font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #f8fafd; "></p><table align="center" width="95%" cellspacing="0" cellpadding="6" border="0" style="color: #000000; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 12px; line-height: 18px; text-align: left; background-color: #f8fafd; border-right-color: #cccccc; table-layout: fixed; border-top-color: #cccccc; border-left-color: #cccccc; border-bottom-color: #cccccc; "><tbody><tr><td bgcolor="#fdfddf" style="word-wrap: break-word; "><p style="font-size: 14px; line-height: 25px; "><span style="background-color: #ffffff; ">var canvas = document.body.appendChild(document.createElement("canvas")),</span></p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">context = canvas.getContext("2d"),</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">a, b, position;</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">// Now I'm going to sample the surface at .1 intervals for a and b parameters:</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">for (a = 0; a &lt; 1; a += .1) {</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">for (b = 0; b &lt; 1; b += .1) {</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">position = surface(a, b);</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">context.fillRect(position.x, position.y, 1, 1);</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">}</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">}</p></td></tr></tbody></table><p style="line-height: 25px; text-align: left; font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #f8fafd; "></p><p style="line-height: 25px; text-align: left; font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #f8fafd; ">这时，看到的效果是这样的：</p><p style="line-height: 25px; text-align: center; font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #f8fafd; "><img width="505" height="244" border="0" alt="" src="http://articles.csdn.net/uploads/allimg/120208/121_120208092416_1.jpg" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; cursor: pointer; " /></p><p style="line-height: 25px; text-align: left; font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #f8fafd; ">现在，尝试一下更密集的采样间隔：</p><p style="line-height: 25px; text-align: center; font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #f8fafd; "><img width="493" height="99" border="0" alt="" src="http://articles.csdn.net/uploads/allimg/120208/121_120208092429_1.jpg" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; cursor: pointer; " /></p><p style="line-height: 25px; text-align: left; font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #f8fafd; ">正如现在所看到的，因为采样间隔越来越密集，点越来越接近，到最高密度时，相邻点之间的距离小于一个像素，肉眼就看不到间隔（见0.01）。为了不造成太大的视觉差，再进一步缩小采样间隔，此时，绘制区已经填满（比较结果为0.01和0.001）。</p><p style="line-height: 25px; text-align: left; font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #f8fafd; ">接下来，我用这个公式来绘制一个圆形：（X-X0）^ 2 +（Y-Y0）^ 2 &lt;半径^ 2，其中（X0，Y0）为圆心：</p><p style="line-height: 25px; text-align: left; font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #f8fafd; "></p><table align="center" width="95%" cellspacing="0" cellpadding="6" border="0" style="color: #000000; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 12px; line-height: 18px; text-align: left; background-color: #f8fafd; border-right-color: #cccccc; table-layout: fixed; border-top-color: #cccccc; border-left-color: #cccccc; border-bottom-color: #cccccc; "><tbody><tr><td bgcolor="#fdfddf" style="word-wrap: break-word; "><p style="font-size: 14px; line-height: 25px; "><span style="background-color: #ffffff; ">function surface(a, b) {</span></p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">var x = a * 100,</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">y = b * 100,</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">radius = 50,</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">x0 = 50,</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">y0 = 50;</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">if ((x - x0) * (x - x0) + (y - y0) * (y - y0) &lt; radius * radius) {</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">// inside the circle</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">return {</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">x: x,</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">y: y</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">};</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">} else {</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">// outside the circle</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">return null;</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">}</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">}</p></td></tr></tbody></table><p style="line-height: 25px; text-align: left; font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #f8fafd; "></p><p style="line-height: 25px; text-align: left; font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #f8fafd; ">为了防止溢出，还要加上一个采样条件：</p><p style="line-height: 25px; text-align: left; font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #f8fafd; "></p><table align="center" width="95%" cellspacing="0" cellpadding="6" border="0" style="color: #000000; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 12px; line-height: 18px; text-align: left; background-color: #f8fafd; border-right-color: #cccccc; table-layout: fixed; border-top-color: #cccccc; border-left-color: #cccccc; border-bottom-color: #cccccc; "><tbody><tr><td bgcolor="#fdfddf" style="word-wrap: break-word; "><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">if (position = surface(a, b)) {</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">context.fillRect(position.x, position.y, 1, 1);</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">}</p></td></tr></tbody></table><p style="line-height: 25px; text-align: left; font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #f8fafd; "></p><p style="line-height: 25px; text-align: left; font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #f8fafd; ">结果如下：</p><p style="line-height: 25px; text-align: center; font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #f8fafd; "><img width="149" height="130" border="0" alt="" src="http://articles.csdn.net/uploads/allimg/120208/121_120208092534_1.jpg" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; cursor: pointer; " /></p><p style="line-height: 25px; text-align: left; font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #f8fafd; ">有不同的方法来定义一个圆，其中一些并不需要拒绝采样。我并无一定要使用哪一种来定义圆圈的意思，所以下面用另一种方法来定义一个圆：</p><p style="line-height: 25px; text-align: left; font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #f8fafd; "></p><table align="center" width="95%" cellspacing="0" cellpadding="6" border="0" style="color: #000000; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 12px; line-height: 18px; text-align: left; background-color: #f8fafd; border-right-color: #cccccc; table-layout: fixed; border-top-color: #cccccc; border-left-color: #cccccc; border-bottom-color: #cccccc; "><tbody><tr><td bgcolor="#fdfddf" style="word-wrap: break-word; "><p style="font-size: 14px; line-height: 25px; ">function surface(a, b) {</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">// Circle using polar coordinates</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">var angle = a * Math.PI * 2,</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">radius = 50,</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">x0 = 50,</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">y0 = 50;</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">return {</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">x: Math.cos(angle) * radius * b + x0,</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">y: Math.sin(angle) * radius * b + y0</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">};</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">}</p></td></tr></tbody></table><p style="line-height: 25px; text-align: left; font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #f8fafd; "></p><p style="line-height: 25px; text-align: left; font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #f8fafd; ">如图：</p><p style="line-height: 25px; text-align: center; font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #f8fafd; "><img width="149" height="130" border="0" alt="" src="http://articles.csdn.net/uploads/allimg/120208/121_120208092611_1.jpg" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; cursor: pointer; " /></p><p style="line-height: 25px; text-align: center; font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #f8fafd; ">（此方法相比前一个方法需要密集采样以进行填充。）</p><p style="line-height: 25px; text-align: left; font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #f8fafd; ">好了，现在让圆变形，以使它看起来更像是一个花瓣：</p><p style="line-height: 25px; text-align: left; font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #f8fafd; "></p><table align="center" width="95%" cellspacing="0" cellpadding="6" border="0" style="color: #000000; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 12px; line-height: 18px; text-align: left; background-color: #f8fafd; border-right-color: #cccccc; table-layout: fixed; border-top-color: #cccccc; border-left-color: #cccccc; border-bottom-color: #cccccc; "><tbody><tr><td bgcolor="#fdfddf" style="word-wrap: break-word; "><p style="font-size: 14px; line-height: 25px; ">function surface(a, b) {</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">var x = a * 100,</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">y = b * 100,</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">radius = 50,</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">x0 = 50,</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">y0 = 50;</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">if ((x - x0) * (x - x0) + (y - y0) * (y - y0) &lt; radius * radius) {</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">return {</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">x: x,</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">y: y * (1 + b) / 2 // deformation</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">};</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">} else {</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">return null;</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">}</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">}</p></td></tr></tbody></table><p style="line-height: 25px; text-align: left; font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #f8fafd; "></p><p style="line-height: 25px; text-align: left; font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #f8fafd; ">结果：</p><p style="line-height: 25px; text-align: center; font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #f8fafd; "><img width="127" height="126" border="0" alt="" src="http://articles.csdn.net/uploads/allimg/120208/121_120208092643_1.jpg" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; cursor: pointer; " /></p><p style="line-height: 25px; text-align: left; font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #f8fafd; ">这看起来已经很像一个玫瑰花瓣的形状了。在这里也可以试试通过修改一些函数数值，将会出现很多有趣的形状。</p><p style="line-height: 25px; text-align: left; font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #f8fafd; ">接下来应该给它添加色彩了：</p><p style="line-height: 25px; text-align: left; font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #f8fafd; "></p><table align="center" width="95%" cellspacing="0" cellpadding="6" border="0" style="color: #000000; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 12px; line-height: 18px; text-align: left; background-color: #f8fafd; border-right-color: #cccccc; table-layout: fixed; border-top-color: #cccccc; border-left-color: #cccccc; border-bottom-color: #cccccc; "><tbody><tr><td bgcolor="#fdfddf" style="word-wrap: break-word; "><p style="font-size: 14px; line-height: 25px; ">function surface(a, b) {</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">var x = a * 100,</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">y = b * 100,</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">radius = 50,</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">x0 = 50,</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">y0 = 50;</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">if ((x - x0) * (x - x0) + (y - y0) * (y - y0) &lt; radius * radius) {</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">return {</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">x: x,</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">y: y * (1 + b) / 2,</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">r: 100 + Math.floor((1 - b) * 155), // this will add a gradient</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">g: 50,</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">b: 50</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">};</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">} else {</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">return null;</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">}</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">}</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">for (a = 0; a &lt; 1; a += .01) {</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">for (b = 0; b &lt; 1; b += .001) {</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">if (point = surface(a, b)) {</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">context.fillStyle = "rgb(" + point.r + "," + point.g + "," + point.b + ")";</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">context.fillRect(point.x, point.y, 1, 1);</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">}</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">}</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">}</p></td></tr></tbody></table><p style="line-height: 25px; text-align: left; font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #f8fafd; "></p><p style="line-height: 25px; text-align: left; font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #f8fafd; ">结果：</p><p style="line-height: 25px; text-align: center; font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #f8fafd; "><img width="159" height="129" border="0" alt="" src="http://articles.csdn.net/uploads/allimg/120208/121_120208092721_1.jpg" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; cursor: pointer; " /></p><p style="line-height: 25px; text-align: left; font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #f8fafd; ">一片带色的花瓣就出现了。</p><p style="line-height: 25px; text-align: left; font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #f8fafd; "><strong>3D曲面和透视投影</strong></p><p style="line-height: 25px; text-align: left; font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #f8fafd; ">定义三维表面很简单，比如，来定义一个管状物体：</p><p style="line-height: 25px; text-align: left; font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #f8fafd; "></p><table align="center" width="95%" cellspacing="0" cellpadding="6" border="0" style="color: #000000; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 12px; line-height: 18px; text-align: left; background-color: #f8fafd; border-right-color: #cccccc; table-layout: fixed; border-top-color: #cccccc; border-left-color: #cccccc; border-bottom-color: #cccccc; "><tbody><tr><td bgcolor="#fdfddf" style="word-wrap: break-word; "><p style="font-size: 14px; line-height: 25px; "><span style="background-color: #ffffff; ">function surface(a, b) {</span></p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">var angle = a * Math.PI * 2,</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">radius = 100,</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">length = 400;</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">return {</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">x: Math.cos(angle) * radius,</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">y: Math.sin(angle) * radius,</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">z: b * length - length / 2, // by subtracting length/2 I have centered the tube at (0, 0, 0)</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">r: 0,</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">g: Math.floor(b * 255),</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">b: 0</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">};</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">}</p></td></tr></tbody></table><p style="line-height: 25px; text-align: left; font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #f8fafd; "></p><p style="line-height: 25px; text-align: left; font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #f8fafd; ">接着添加投影透视图，首先需要我们定义一个摄像头：</p><p style="line-height: 25px; text-align: center; font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #f8fafd; "><img width="429" height="288" border="0" alt="" src="http://articles.csdn.net/uploads/allimg/120208/121_120208092808_1.jpg" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; cursor: pointer; " /></p><p style="line-height: 25px; text-align: left; font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #f8fafd; ">如上图，将摄像头放置在（0，0，Z）位置，画布在X / Y平面。投影到画布上的采样点为：</p><p style="line-height: 25px; text-align: left; font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #f8fafd; "></p><table align="center" width="95%" cellspacing="0" cellpadding="6" border="0" style="color: #000000; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 12px; line-height: 18px; text-align: left; background-color: #f8fafd; border-right-color: #cccccc; table-layout: fixed; border-top-color: #cccccc; border-left-color: #cccccc; border-bottom-color: #cccccc; "><tbody><tr><td bgcolor="#fdfddf" style="word-wrap: break-word; "><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">var pX, pY, // projected on canvas x and y coordinates</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">perspective = 350,</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">halfHeight = canvas.height / 2,</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">halfWidth = canvas.width / 2,</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">cameraZ = -700;</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">for (a = 0; a &lt; 1; a += .001) {</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">for (b = 0; b &lt; 1; b += .01) {</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">if (point = surface(a, b)) {</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">pX = (point.x * perspective) / (point.z - cameraZ) + halfWidth;</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">pY = (point.y * perspective) / (point.z - cameraZ) + halfHeight;</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">context.fillStyle = "rgb(" + point.r + "," + point.g + "," + point.b + ")";</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">context.fillRect(pX, pY, 1, 1);</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">}</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">}</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">}</p></td></tr></tbody></table><p style="line-height: 25px; text-align: left; font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #f8fafd; "></p><p style="line-height: 25px; text-align: left; font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #f8fafd; ">效果为：</p><p style="line-height: 25px; text-align: center; font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #f8fafd; "><img width="194" height="176" border="0" alt="" src="http://articles.csdn.net/uploads/allimg/120208/121_120208092837_1.jpg" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; cursor: pointer; " /></p><p style="line-height: 25px; text-align: left; font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #f8fafd; "><strong>z-buffer</strong></p><p style="line-height: 25px; text-align: left; font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #f8fafd; ">z-buffer在计算机图形学中是一个相当普遍的技术，在为物件进行着色时，执行&#8220;隐藏面消除&#8221;工作，使隐藏物件背后的部分就不会被显示出来。</p><p style="line-height: 25px; text-align: center; font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #f8fafd; "><img width="318" height="316" border="0" alt="" src="http://articles.csdn.net/uploads/allimg/120208/121_120208092913_1.jpg" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; cursor: pointer; " /></p><p style="line-height: 25px; text-align: left; font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #f8fafd; ">上图是用z-buffer技术处理后的玫瑰。(可以看到已经具有立体感了)</p><p style="line-height: 25px; text-align: left; font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #f8fafd; ">代码如下：</p><p style="line-height: 25px; text-align: left; font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #f8fafd; "></p><table align="center" width="95%" cellspacing="0" cellpadding="6" border="0" style="color: #000000; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 12px; line-height: 18px; text-align: left; background-color: #f8fafd; border-right-color: #cccccc; table-layout: fixed; border-top-color: #cccccc; border-left-color: #cccccc; border-bottom-color: #cccccc; "><tbody><tr><td bgcolor="#fdfddf" style="word-wrap: break-word; "><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">var zBuffer = [],</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">zBufferIndex;</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">for (a = 0; a &lt; 1; a += .001) {</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">for (b = 0; b &lt; 1; b += .01) {</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">if (point = surface(a, b)) {</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">pX = Math.floor((point.x * perspective) / (point.z - cameraZ) + halfWidth);</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">pY = Math.floor((point.y * perspective) / (point.z - cameraZ) + halfHeight);</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">zBufferIndex = pY * canvas.width + pX;</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">if ((typeof zBuffer[zBufferIndex] === "undefined") || (point.z &lt; zBuffer[zBufferIndex])) {</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">zBuffer[zBufferIndex] = point.z;</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">context.fillStyle = "rgb(" + point.r + "," + point.g + "," + point.b + ")";</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">context.fillRect(pX, pY, 1, 1);</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">}</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">}</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">}</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">}</p></td></tr></tbody></table><p style="line-height: 25px; text-align: left; font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #f8fafd; "></p><p style="line-height: 25px; text-align: left; font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #f8fafd; "><strong>旋转</strong></p><p style="line-height: 25px; text-align: left; font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #f8fafd; ">你可以使用任何矢量旋转的方法。在代码玫瑰的创建中，我使用的是欧拉旋转。现在将之前编写的管状物进行旋转，实现绕Y轴旋转：</p><p style="line-height: 25px; text-align: left; font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #f8fafd; "></p><table align="center" width="95%" cellspacing="0" cellpadding="6" border="0" style="color: #000000; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 12px; line-height: 18px; text-align: left; background-color: #f8fafd; border-right-color: #cccccc; table-layout: fixed; border-top-color: #cccccc; border-left-color: #cccccc; border-bottom-color: #cccccc; "><tbody><tr><td bgcolor="#fdfddf" style="word-wrap: break-word; "><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">function surface(a, b) {</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">var angle = a * Math.PI * 2,</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">radius = 100,</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">length = 400,</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">x = Math.cos(angle) * radius,</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">y = Math.sin(angle) * radius,</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">z = b * length - length / 2,</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">yAxisRotationAngle = -.4, // in radians!</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">rotatedX = x * Math.cos(yAxisRotationAngle) + z * Math.sin(yAxisRotationAngle),</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">rotatedZ = x * -Math.sin(yAxisRotationAngle) + z * Math.cos(yAxisRotationAngle);</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">return {</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">x: rotatedX,</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">y: y,</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">z: rotatedZ,</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">r: 0,</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">g: Math.floor(b * 255),</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">b: 0</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">};</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">}</p></td></tr></tbody></table><p style="line-height: 25px; text-align: left; font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #f8fafd; "></p><p style="line-height: 25px; text-align: left; font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #f8fafd; ">效果：</p><p style="line-height: 25px; text-align: center; font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #f8fafd; "><img width="235" height="179" border="0" alt="" src="http://articles.csdn.net/uploads/allimg/120208/121_120208093034_1.jpg" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; cursor: pointer; " /></p><p style="line-height: 25px; text-align: left; font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #f8fafd; "><strong>蒙特卡罗方法</strong></p><p style="line-height: 25px; text-align: left; font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #f8fafd; ">关于采样时间，间隔过大过小都会引起极差的视觉感受，所以，需要设置合理的采样间隔，这里使用蒙特卡罗方法。</p><p style="line-height: 25px; text-align: left; font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #f8fafd; "></p><table align="center" width="95%" cellspacing="0" cellpadding="6" border="0" style="color: #000000; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 12px; line-height: 18px; text-align: left; background-color: #f8fafd; border-right-color: #cccccc; table-layout: fixed; border-top-color: #cccccc; border-left-color: #cccccc; border-bottom-color: #cccccc; "><tbody><tr><td bgcolor="#fdfddf" style="word-wrap: break-word; "><p style="font-size: 14px; line-height: 25px; ">var i;</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">window.setInterval(function () {</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">for (i = 0; i &lt; 10000; i++) {</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">if (point = surface(Math.random(), Math.random())) {</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">pX = Math.floor((point.x * perspective) / (point.z - cameraZ) + halfWidth);</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">pY = Math.floor((point.y * perspective) / (point.z - cameraZ) + halfHeight);</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">zBufferIndex = pY * canvas.width + pX;</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">if ((typeof zBuffer[zBufferIndex] === "undefined") || (point.z &lt; zBuffer[zBufferIndex])) {</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">zBuffer[zBufferIndex] = point.z;</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">context.fillStyle = "rgb(" + point.r + "," + point.g + "," + point.b + ")";</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">context.fillRect(pX, pY, 1, 1);</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">}</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">}</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">}</p><p style="font-size: 14px; line-height: 25px; background-color: #ffffff; ">}, 0);</p></td></tr></tbody></table><p style="line-height: 25px; text-align: left; font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #f8fafd; "></p><p style="line-height: 25px; text-align: left; font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #f8fafd; ">设置a和b为随机参数，用足够的采样完成表面填充。我每次绘制10000点，然后静待屏幕完成更新。</p><p style="line-height: 25px; text-align: left; font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #f8fafd; ">另外需要注意的是，如果随机数发生错误时，表面填充效果会出错。有些浏览器中，Math.random的执行是线性的，这就有可能导致表面填充效果出错。这时，就得使用类似Mersenne Twister（一种随机数算法）这样的东西去进行高质量的PRNG采样，从而避免错误的发生。</p><p style="line-height: 25px; text-align: left; font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #f8fafd; "><strong>完成</strong></p><p style="line-height: 25px; text-align: left; font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #f8fafd; ">为了使玫瑰的每个部分在同一时间完成并呈现，还需要添加一个功能，为每部分设置一个参数以返回值来进行同步。并用一个分段函数代表玫瑰的各个部分。比如在花瓣部分，我用旋转和变形来创建它们。</p><p style="line-height: 25px; text-align: left; font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #f8fafd; ">虽然表面采样方法是创建三维图形非常著名的、最古老的方法之一，但这种把蒙特卡罗、z-buffer加入到表面采样中的方法并不常见。对于现实生活场景的制作，这也许算不上很有创意，但它简易的代码实现和很小的体积仍令人满意。</p><p style="line-height: 25px; text-align: left; font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #f8fafd; ">希望这篇文章能激发计算机图形学爱好者来尝试不同的呈现方法，并从中获得乐趣。（Roman Cortes）</p><p style="line-height: 25px; text-align: left; font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #f8fafd; ">英文原址：<a target="_blank" href="http://www.romancortes.com/blog/1k-rose/" style="color: #015fb6; text-decoration: none; ">romancortes.com&nbsp;</a></p></div><img src ="http://www.blogjava.net/xiaomage234/aggbug/369728.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/xiaomage234/" target="_blank">小马歌</a> 2012-02-10 11:59 <a href="http://www.blogjava.net/xiaomage234/archive/2012/02/10/369728.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>HTML5在Android iOS等移动平台上的兼容性</title><link>http://www.blogjava.net/xiaomage234/archive/2012/02/09/369682.html</link><dc:creator>小马歌</dc:creator><author>小马歌</author><pubDate>Thu, 09 Feb 2012 08:07:00 GMT</pubDate><guid>http://www.blogjava.net/xiaomage234/archive/2012/02/09/369682.html</guid><wfw:comment>http://www.blogjava.net/xiaomage234/comments/369682.html</wfw:comment><comments>http://www.blogjava.net/xiaomage234/archive/2012/02/09/369682.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/xiaomage234/comments/commentRss/369682.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/xiaomage234/services/trackbacks/369682.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 最近尝试将做的一个Android项目web化，而其中的一个方案，就是做成html5的。于是做了一些Demo，也做了一些简单的研究。其中一个比较重要的问题，就是HTML5在Android和IOS的兼容性如何。找到下面的表格，很好的解答了我的问题。与看到这篇博文的好友一起分享。FeatureSafari on iOSAndroid&nbsp;BrowserBlackBerry BrowserNokia...&nbsp;&nbsp;<a href='http://www.blogjava.net/xiaomage234/archive/2012/02/09/369682.html'>阅读全文</a><img src ="http://www.blogjava.net/xiaomage234/aggbug/369682.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/xiaomage234/" target="_blank">小马歌</a> 2012-02-09 16:07 <a href="http://www.blogjava.net/xiaomage234/archive/2012/02/09/369682.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>