


HTML5/CSS3 classic case - drag and drop to upload images without plug-in (2)
The previous article has implemented the overall HTML and CSS of this project:
# #HTML5/CSS3 Classic Case - Drag and Drop to Upload Pictures without Plugins (1)
This blog is directly based on the previous one. The final effect is:
Rendering 1:
You can see it The html of the li that produces our pictures is actually quite complicated, so I made some modifications to the html document:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
You can see me The display of li is written independently to a p#template. The default is hidden. What are the benefits of doing this? To avoid a large amount of code for creating elements and assigning attributes in js every time we upload a file, we generally design the generation of more complex html elements. It is recommended to use this method, which can simplify the code and also facilitate the later maintenance of our code.
Js code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
|
The comments are very detailed. This time I didn’t use literals to create objects directly because I didn’t I hope that users can access all methods and variables. I use simple closures. It can be seen that almost all methods and variables start with _ because I think they are private and I have not published them. The only ones that are published are It is the init method for users to call. The overall method also uses namespaces, so that the js written by other partners basically does not cause the same problems as variables.
HTML FileApi is used in the above js. Here is an introduction:
1. File object That is what we used above:
- ## lastModifiedDate
: Thu Dec 26 2013 18:45:08 GMT+0800 (China Standard Time)
name : "yt_key.png"
##size- :
45524
type - :
"image/png"
webkitRelativePath - :
""##__proto__
: FileYou can see that some of the above attributes are included. That is to say, if you use a browser that supports HTML5 and set the onchange event for input=type, the user After selecting a picture or file, you can make a judgment about the display of the picture or the size and type of the file.
2、FileReader主要用于异步读取文件内容,注意是异步的,上例我们使用了它的readAsDataURL的方法,关于DataUri的知识可以自己去百度下。
另外还提供了:readAsText用于读取文本;readAsArrayBuffer和readAsBinaryString方法;
还提供了一些事件:onloadstart, onload, onprogress ,onerror , onloaded , onabort 有兴趣的可以去一个一个查看。
最后页面调用,大功告成:
1
2
3
4
5
6
7
8
9
10
11
12
<span style=
"font-size:12px;"
> <script type=
"text/javascript"
src=
"jquery-1.8.3.js"
></script>
<script type=
"text/javascript"
src=
"js/html5upload.js"
></script>
<script type=
"text/javascript"
>
window.onload =
function
()
{
ZhangHongyang.html5upload.init();
}
;
</script></span>
Copy after loginThe above is the detailed content of HTML5/CSS3 classic case - drag and drop to upload images without plug-in (2). For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











Guide to Table Border in HTML. Here we discuss multiple ways for defining table-border with examples of the Table Border in HTML.

This is a guide to Nested Table in HTML. Here we discuss how to create a table within the table along with the respective examples.

Guide to HTML margin-left. Here we discuss a brief overview on HTML margin-left and its Examples along with its Code Implementation.

Guide to HTML Table Layout. Here we discuss the Values of HTML Table Layout along with the examples and outputs n detail.

Guide to HTML Input Placeholder. Here we discuss the Examples of HTML Input Placeholder along with the codes and outputs.

Guide to the HTML Ordered List. Here we also discuss introduction of HTML Ordered list and types along with their example respectively

Guide to HTML onclick Button. Here we discuss their introduction, working, examples and onclick Event in various events respectively.

Guide to Moving Text in HTML. Here we discuss an introduction, how marquee tag work with syntax and examples to implement.
