-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcanvasLine.html
186 lines (161 loc) · 5.9 KB
/
canvasLine.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>响应式图片</title>
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no">
<link rel="stylesheet" href="aaa.css">
<title>Document</title>
<style>
html,body{
margin: 0;
padding: 0;
}
</style>
</head>
<body style="background: snow;position: absolute;">
<div class="awd-site-bg" >
<canvas id="awd-site-canvas" width="414" height="736"></canvas>
</div>
<div class="awd-site-bg" id="b" style='top:266px;left:160px;'></div>
<div id='a' style="width: 100px;height: 500px;text-align:center;padding-top:200px;z-index: 13;backface-visibility: hidden;
-webkit-perspective: 1000;position: relative;">a
</div>
<!-- <img src="https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=2285831821,1738537271&fm=27&gp=0.jpg"
srcset="https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=2285831821,1738537271&fm=27&gp=0.jpg 533w,https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1511776959657&di=e7a5ff5df1494893a4c17e4b55fe3d69&imgtype=0&src=http%3A%2F%2Fpic74.nipic.com%2Ffile%2F20150728%2F18138004_201107753000_2.jpg 924w"
sizes="(max-width:600px)500px,1000px">
<a id="alink" href="http://www.baidu.com">下一步</a> -->
<img src="images/1_01.png" alt="">
</body>
<script type="text/javascript" src="jq.js"></script>
<script>
$("#a").click(function(){
$("#b").addClass('active')
})
</script>
<script>
var canvas = document.getElementById("awd-site-canvas");
var ctx = canvas.getContext("2d");
window.requestAnimFrame = (function () {
return window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
function (callback) {
window.setTimeout(callback, 1000 / 60);
};
})();
var curves_array = [];
var curve = function (cp1x, cp1y, cp2x, cp2y, x, y, cp1xvx, cp1xvy, cp1yvx, cp1yvy, cp2xvx, cp2xvy, cp2yvx, cp2yvy) {
this.cp1x = cp1x;
this.cp1y = cp1y;
this.cp2x = cp2x;
this.cp2y = cp2y;
this.x = x;
this.y = y;
this.cp1xvx = cp1xvx;
this.cp1xvy = cp1xvy;
this.cp1yvx = cp1yvx;
this.cp1yvy = cp1yvy;
this.cp2xvx = cp2xvx;
this.cp2xvy = cp2xvy;
this.cp2yvx = cp2yvx;
this.cp2yvy = cp2yvy;
};
function awdCanvasResize() {
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
}
function awdCanvasInit() {
var awd_bg_number_of_curves = 20;
for (var i = 0; i < awd_bg_number_of_curves; i++) {
var cp1x = Math.random() * canvas.width;//200
var cp1y = Math.random() * canvas.height;//300
var cp2x = Math.random() * canvas.width;//300
var cp2y = Math.random() * canvas.height;//200
var x = 0;
var y = 0;
var cp1xvx = Math.random() * 2- 1;//0.8
var cp1xvy = Math.random() * 2 - 1;//0.2
var cp1yvx = Math.random() * 2 - 1;
var cp1yvy = Math.random() * 2 - 1;
var cp2xvx= Math.random() * 2 - 1;
var cp2xvy= Math.random() * 2 - 1;
var cp2yvx = Math.random() * 2 - 1;
var cp2yvy = Math.random() * 2 - 1;
curves_array.push(
new curve(
cp1x, cp1y, cp2x, cp2y,
x, y,
cp1xvx,cp1xvy,cp1yvx,cp1yvy,
cp2xvx,cp2xvy,cp2yvx,cp2yvy
)
);
}
}
function awdCanvasDraw() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.lineWidth = 1;
ctx.strokeStyle = $("#awd-site-wrap").css('color');
for (var i = 0; i < curves_array.length; i++) {
ctx.beginPath();
ctx.moveTo(-100, canvas.height + 100);
ctx.bezierCurveTo(
curves_array[i].cp1x, curves_array[i].cp1y,
curves_array[i].cp2x, curves_array[i].cp2y,
canvas.width + 100, curves_array[i].y - 100
);
ctx.stroke();
if (curves_array[i].cp1x < 0 || curves_array[i].cp1x > canvas.width) {
curves_array[i].cp1x -= curves_array[i].cp1xvx;
curves_array[i].cp1xvx *= -1;
}
if (curves_array[i].cp1y < 0 || curves_array[i].cp1y > canvas.height) {
curves_array[i].cp1y -= curves_array[i].cp1yvy;
curves_array[i].cp1yvy *= -1;
}
if (curves_array[i].cp2x < 0 || curves_array[i].cp2x > canvas.width) {
curves_array[i].cp2x -= curves_array[i].cp2xvx;
curves_array[i].cp2xvx *= -1;
}
if (curves_array[i].cp2y < 0 || curves_array[i].cp2y > canvas.height) {
curves_array[i].cp2y -= curves_array[i].cp2yvy;
curves_array[i].cp2yvy *= -1;
}
curves_array[i].cp1y += curves_array[i].cp1yvy;
curves_array[i].cp1x += curves_array[i].cp1xvx;
curves_array[i].cp2x += curves_array[i].cp2xvx;
}
requestAnimFrame(awdCanvasDraw);
}
function awdCanvas(){
awdCanvasResize();
awdCanvasInit();
awdCanvasDraw();
}
awdCanvas();
</script>
</html>
<!--
图片从中心开始放大显示
var c=document.getElementById("test");
var cxt=c.getContext("2d");
//cxt.fillStyle = "white";
//cxt.fillRect(0,0,100,100);
var img=new Image()
img.src="./a.jpg"
img.onload = function(){
var i =0;
changeC(i);
};
function changeC(i){
setInterval(function(){
cxt.save();
cxt.arc(50,50,1+i,0,2*Math.PI);
cxt.clip();
cxt.drawImage(img,0,0,100,100);
i+=5;
cxt.restore();
},60)
} -->
<!-- 533w和1024w代表图片的素质,
和sizes里的500px和1000px做对应,533大于500,所以用了533w,1024w大于1000px,所以用了1024w -->