-
Notifications
You must be signed in to change notification settings - Fork 0
/
canvas.js
112 lines (104 loc) · 3.5 KB
/
canvas.js
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
//环形图动画
var buffer = [], canvasBuffer = [];
function startDraw(t, index) {
var target = t * 3.6;
canvasBuffer[index].clearRect(0, 0, 70, 70);
canvasBuffer[index].beginPath();
canvasBuffer[index].lineWidth = 5;
canvasBuffer[index].strokeStyle = "#3fb5ff";
var circle = {
x: 35,
y: 35,
r: 32
};
if ((Math.PI * 2) - (Math.PI / 180) * target - 0.5 * Math.PI < -1.570) {
canvasBuffer[index].arc(circle.x, circle.y, circle.r, -0.5 * Math.PI, -1.570, true);
} else {
canvasBuffer[index].arc(circle.x, circle.y, circle.r, -0.5 * Math.PI, (Math.PI * 2) - (Math.PI / 180) * target - 0.5 * Math.PI, true);
}
//
canvasBuffer[index].stroke();
}
function draw(canvas,index) {
var target = parseInt(canvas.parent().parent().find('span').text()), start = 0;
var _num = target % 7;
if(target>=7){
target -= _num;
}
canvasBuffer[index] = canvas[0].getContext("2d");
if(target==0){
return;
}
window.clearInterval(buffer[index]);
buffer[index] = setInterval(function () {
start += 7;
if (start <= target) {
startDraw(start, index);
}
else {
if(target>=7){
target += _num;
}
startDraw(target, index);
clearInterval(buffer[index]);
}
}, 45);
}
function remainingTime(timeDel,btn){
if(timeDel>0){
var timeString="";
var days=parseInt(timeDel/60/60/24);
var hours=parseInt((timeDel/60/60)-days*24);
var minute=parseInt((timeDel/60)-days*24*60-hours*60);
var senconds=parseInt(timeDel-days*24*60*60-hours*60*60-minute*60);
if(days>0){
timeString=timeString+days+"天";
}else
{
timeString="00天";
}
if(hours>9){
timeString=timeString+hours+"时";
}else{
timeString=timeString+"0"+hours+"时";
}
if(minute>9){
timeString=timeString+minute+"分";
}else{
timeString=timeString+minute+"分";
}
if(senconds>9){
timeString=timeString+senconds+"秒";
}else{
timeString=timeString+senconds+"秒";
}
btn.text(timeString+" 开售");
}
else{
if(!btn.hasClass("btn-grab")){
btn.removeClass("btn-wait");
btn.addClass("btn-grab");
btn.text("立即抢购");
}
}
}
function reflash() {
//如果重新排序是ajax请求重新改变dom记得再次使用次循环
$(".btn-wait").each(function(index){
var endTime=Date.parse($(this).data("time"));
var now=Date.parse(new Date());
var timeDel=(endTime-now)/1000;
var btn=$(this);
remainingTime(timeDel,btn);
timeDel--;
setInterval(function(){
remainingTime(timeDel--,btn);
},1000);
});
//每次加载或者选择的时候请再次执行这个动画
$(".canvasCircle.unslide").each(function (index, el) {
$(this).removeClass("unslide");
draw($(this),index);
});
}
queryForProductList(start,limit);