-
Notifications
You must be signed in to change notification settings - Fork 0
/
html5.html
304 lines (277 loc) · 9.7 KB
/
html5.html
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
<!DOCTYPE html>
<html lang="zh">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="icon" href="./favicon.ico" type="image/x-icon" />
<title>html5笔记 | 学习笔记</title>
<style>
* {
margin: 0;
padding: 0;
}
#div1 {background: red; width: 200px; height: 150px;}
.drag, .position {
margin-top: 20px;
}
#allmap {width: 400px;height:300px;}
.canvas {
position: relative;
width: 300px;
margin-top: 20px;
}
.canvas select {
position:absolute;
top:0;
right:0;
}
</style>
</head>
<body>
<div style="text-align:center;height: 346px;">
<button onclick="playPause()">播放/暂停</button>
<button onclick="makeBig()">大</button>
<button onclick="makeNormal()">中</button>
<button onclick="makeSmall()">小</button>
<select id="select" onchange="volume()" >
<option value="L">1</option>
<option value="M">0.5</option>
<option value="S">0</option>
</select>
<br />
<video id="video1" width="420" controls poster="https://www.runoob.com/images/img_the_scream.jpg" >
<!-- autoplay muted静音下自动播放video,兼容Chrome -->
<!-- mp4兼容IE,Safari和Chrome。ogg(优),webm兼容Chrome,Firefox和Opera -->
<source type="video/ogg" src="file:///C:/Users/lenovo/Desktop/慢才后生的网页/《奇幻森林》中文预告国语流畅.ogg" />
<source src="http://www.w3school.com.cn/example/html5/mov_bbb.mp4" type="video/mp4" />
<source src="http://www.w3school.com.cn/i/movie.ogg" type="video/ogg" />
Your browser does not support HTML5 video.
</video>
</div>
<audio controls muted autoplay loop style="background: red;">
<!-- autoplay自动播放audio,video(IE可行) -->
<source type="audio/mp3" src="http://www.ytmp3.cn/down/36706.mp3" />
</audio>
<a href="mailto:1260750674@qq.com;z1260750674@gmail.com?cc=name1@163.com&bcc=name2@139.com
&subject=哈%20哈
&body=邮%20件%20内%20容" target="_blank">邮件联系我</a>
<span style="cursor: pointer;" onclick="window.location.href='http://www.baidu.com';">百度一下</span>
<div class="drag">
<img id="drag1" src="https://www.runoob.com/images/img_the_scream.jpg" draggable="true" ondragstart="drag(event)" heidth="336px" height="69px" title="鼠标把我拖动到红框里" />
<div id="div1" ondrop="drop(event)" ondragover="allowDrop(event)"></div>
</div>
<div class="position">
<div id="allmap"></div>
<p>实际GPS坐标:纬度31.29444 经度121.48055</p>
WGS84 坐标:<p id="demo1"></p>
百度去偏坐标:<p id="demo2"></p>
<button onclick="getLocation()">获取位置</button><br />
</div>
<div class="canvas">
<canvas id="mycanvas" style="background: gray" width="220" height="200"></canvas>
<select id="select-mycanvas" onchange="mycanvas()" >
<option value="" selected="selected" disabled>选择形状</option>
<option value="rect">矩形</option>
<option value="line">线条</option>
<option value="arc">圆</option>
<option value="text">文本</option>
<option value="linear">径向渐变</option>
<option value="img">画布图像</option>
</select>
<ul style="font-size: 14px;">
<li><a href="./canvas定位鼠标光标位置.html">canvas定位鼠标光标位置</a></li>
<li><a href="./canvas lineWidth.html">canvas lineWidth</a></li>
</ul>
</div>
<svg width="180" height="140" xmlns="http://www.w3.org/2000/svg">
<!-- Created with Method Draw - http://github.com/duopixel/Method-Draw/ -->
<g>
<title>SVG</title>
<path stroke="null" height="142" width="182" y="-1" x="-1" id="canvas_background" d="m-0.5,-0.49999l175.99999,0l0,141.99998l-175.99999,0l0,-141.99998z" stroke-opacity="null" stroke-linecap="null" stroke-linejoin="null" stroke-width="null" fill-opacity="null" fill="#fff"/>
<g display="none" id="canvasGrid">
<rect fill="url(#gridpattern)" stroke-width="0" y="1" x="1" height="480" width="640" id="svg_3"/>
</g>
<rect id="svg_1" height="60" width="120" y="40" x="30" stroke-width="1.5" fill="#fff" stroke="#000"/>
<ellipse ry="30" rx="26" id="svg_2" cy="70" cx="90" stroke-width="1.5" stroke="#000" fill="#fff"/>
</g>
</svg>
<script type="text/javascript">
function mycanvas(){
var c = document.getElementById("mycanvas");
var ctx = c.getContext("2d");
function rect(obj){
obj.fillStyle="#FF0000";
obj.fillRect(0,0,150,75);
/*
obj.rect(0,0,150,75);
obj.fill();
*/
}
function line(obj){
obj.moveTo(0,0);
obj.lineTo(200,100);
obj.stroke();
}
function arc(obj){
obj.beginPath();
obj.arc(95,60,40,0,2*Math.PI);
obj.stroke();
}
function text(obj){
obj.font="30px Arial";
obj.fillText("Hello World",10,50);
}
function linear(obj){
// 创建渐变
var grd=obj.createLinearGradient(0,0,200,0); //圆渐变 createRadialGradient()
grd.addColorStop(0,"red");
grd.addColorStop(1,"white");
// 填充渐变
obj.fillStyle=grd;
obj.fillRect(10,10,150,80);
}
function drawImage(obj){
var img=document.getElementById("scream");
obj.drawImage(img,10,10);
}
var select = document.getElementById("select-mycanvas");
if(select.value==="rect"){
rect(ctx);
}else if(select.value==="line"){
line(ctx);
}else if(select.value==="arc"){
arc(ctx);
}else if(select.value==="text"){
text(ctx);
}else if(select.value==="linear"){
linear(ctx);
}else if(select.value==="img"){
drawImage(ctx);
}
}
</script>
<script>
function drag(ev) {
document.body.ondrop = function(event) {
event.preventDefault();
event.stopPropagation();
}
ev.dataTransfer.setData("Text", ev.target.id);
//alert(ev.target.id);
}
function allowDrop(ev) {
ev.preventDefault(); //避免浏览器对数据的默认处理(drop 事件的默认行为是以链接形式打开)
}
function drop(ev) {
var data = ev.dataTransfer.getData("Text"); //返回在 setData() 方法中设置为相同类型的任何数据
ev.target.appendChild(document.getElementById(data)); //被拖数据是被拖元素的 id ("drag1")
}
</script>
<script type="text/javascript">
var myVideo = document.getElementById("video1");
function playPause()
{
if (myVideo.paused)
myVideo.play();
else
myVideo.pause();
}
function makeBig()
{
myVideo.width= "560";
}
function makeSmall()
{
myVideo.width= "320";
}
function makeNormal()
{
myVideo.width= "420";
}
var select = document.getElementById("select");
function volume()
{
if(select.value==='L')
myVideo.volume = 1;
else if(select.value==='M')
myVideo.volume = 0.5;
else if (select.value==='S')
myVideo.volume = 0;
//已选option的 索引,value,音量
alert("index:"+select.selectedIndex + "\n value:" + select.value + "\n 音量:"+ myVideo.volume);
/* select.options[select.selectedIndex].value, select[select.selectedIndex].value 同 select.value */
//console.log(select.innerHTML); //select.innerText没有反应???
//注意:select.options[select.selectedIndex] 与 select[select.selectedIndex] 完全相同!!
//获取下拉列表 已选项的内容 的两种方式(select.options[select.selectedIndex].innerHTML 同 select.options[select.selectedIndex].text)
/*
//select对象中 索引为selectedIndex的 option选项的内容
alert("选项内容:" + select.options[select.selectedIndex].innerHTML);
*/
/*
for (var i=0;i<select.length;i++) {//下拉框的长度就是它的选项数.
if (select.options[i].selected == true )
alert("选项内容:" + select.options[i].text);//获取 当前选择项 的文本(text属性设置或返回的是包含在 <option> 元素中的纯文本).
}
// 其实本质就是:alert("选项内容:" + select.options[select.selectedIndex].text);
*/
}
</script>
<script type="text/javascript" src="https://api.map.baidu.com/api?v=2.0&ak=fft5rG0OGkhTSPABMsnEplwBXVrM1Nvi&s=1"></script>
<script>
var demo1=document.getElementById("demo1");
var demo2=document.getElementById("demo2");
// 先定位到 北京
var bm = new BMap.Map("allmap");
bm.centerAndZoom(new BMap.Point(116.331398,39.897445),10);
bm.addControl(new BMap.NavigationControl());
bm.enableScrollWheelZoom(true);
function getLocation(){
var options = {
enableHighAccuracy: true,
timeout: 10000,
maximumAge: 10
};
function success(pos) {
var crd = pos.coords;
//直接定位到 GPS坐标
var x = crd.longitude; //经度
var y = crd.latitude; //纬度
demo1.innerHTML = '纬度: ' + y + ' 经度: ' + x + '误差 ' + crd.accuracy+'米';
x = 121.4797129076,y = 31.2950211612;
var ggPoint = new BMap.Point(x,y);
bm.centerAndZoom(ggPoint, 15);
//添加gps marker和label
var markergg = new BMap.Marker(ggPoint);
bm.addOverlay(markergg); //添加GPS marker
var labelgg = new BMap.Label("未转换的GPS坐标(错误)",{offset:new BMap.Size(20,-10)});
markergg.setLabel(labelgg); //添加GPS label
//坐标转换完之后的回调函数
translateCallback = function (data){
if(data.status === 0) {
var marker = new BMap.Marker(data.points[0]);
bm.addOverlay(marker);
var label = new BMap.Label("转换后的百度坐标(正确)",{offset:new BMap.Size(20,-10)});
marker.setLabel(label); //添加百度label
bm.setCenter(data.points[0]); //以正确标记作为 地图中心
demo2.innerHTML = '纬度: ' + data.points[0].lat + ' 经度: ' + data.points[0].lng;
}
}
setTimeout(function(){
var convertor = new BMap.Convertor();
var pointArr = [];
pointArr.push(ggPoint);
convertor.translate(pointArr,1,5,translateCallback)
}, 1000);
}
function error(err) {
console.warn('ERROR(' + err.code + '): ' + err.message);
}
//判断浏览器是否支持定位
if (navigator.geolocation){
navigator.geolocation.getCurrentPosition(success, error, options);
}else{
demo1.innerHTML="该浏览器不支持获取地理位置。";
}
}
</script>
</body>
</html>