商品 | 价格 | 图片 |
---|
var liElements = document.querySelectorAll('li');
var tbodyElements = document.querySelector('.table tbody');
liElements.forEach(function (li) {
soldOut(li);
});
function soldOut(li) {
/*
* 以其中给一个li来做逻辑处理
* */
var buttonElement = li.querySelector('button');
var text1Element = li.querySelector('.text1');
var maskElement = li.querySelector('.mask');
var soldOutElement = li.querySelector('.sold_out');
var timeSpanElement = li.querySelectorAll('.time span');
var goodsName = li.querySelector('.goods_name').innerHTML;
var goodsPrice = li.querySelector('.goods_price').innerHTML;
var goodsImg = li.querySelector('.img').src;
/*
* 点击按钮获取倒计时的时间
* */
buttonElement.onclick = function() {
var seconds = parseInt(text1Element.value);
/*
* 把seconds变成时分秒的格式,并计算倒计时
* */
var timer = setInterval(function () {
seconds--;
if (seconds >= 0) {
var timeArr = seconds2HMS(seconds).split('');
timeArr.forEach(function (item, index) {
timeSpanElement[index].innerHTML = item;
});
} else {
//时间到了
clearInterval(timer);
timeOver();
add2List();
}
}, 1000);
};
function timeOver() {
maskElement.style.display = 'block';
// maskElement.style.opacity = '0.5';
animation(maskElement, {
opacity: 0.5
}, 500);
soldOutElement.style.display = 'block';
animation(soldOutElement, {
width: 198,
height: 198,
left: 61,
top: 76,
opacity: 1
}, 500, 'bounceOut');
setTimeout(function () {
shake(li, 'left', 20, 2);
}, 200);
}
/*
* 添加当前的商品信息到表格列表中
* */
function add2List() {
tbodyElements.innerHTML += '
// animation(trElements[trElements.length - 1], {
// opacity: 1
// 100); }, 100);
}, 1000);
}
var H = addZero(parseInt(seconds / 3600));
var M = addZero(parseInt(seconds % 3600 / 60));
var S = addZero(parseInt (seconds % 60));
}
return (v < 10 ? '0' : '') + v;
}
/*
* Tremble!
function shake(element, attr, range, step) {
/*
* */
var OriginValue = getCSS (Element, Attr);
* Represents+or-
**/
Var Flag = TRUE;
Var Timer = Setinterval (function () () {
if (flag) {
element.style[ Attr] = Originvalue + Range + 'PX';
Range- = STEP;
## If (Range & LT; = 0) {
Element.style [ATTR] = originValue + 'px';
= originValue + 'px'; #}
function getCss(element, attr) {
return parseFloat(element.currentStyle ? element.currentStyle[attr] : getComputedStyle(element)[attr]); ;/script>
if (ele. timer) {
return;
}
var d = duration || 1000;
var obj = {};
for (var attr in attrs) {
obj[attr].b = parseFloat(getComputedStyle(ele)[attr]); obj[attr].c = attrs[attr] - obj[attr].b;
}
var fx = fx || 'linear';
var callback = callback || function(){};
var startTime = Date.now();
ele.timer = setInterval(function () {
var t = Date.now() - startTime;
if (t >= d) {
t = d;
}
for (var attr in attrs) {
var value = Tween[fx](t, obj[attr].b, obj[attr].c, d);
if (attr == 'opacity') {
ele.style[attr] = value;
} else {
ele.style[attr] = value + 'px';
}
}
if (t == d) {
clearInterval(ele.timer);
ele.timer = null;
callback();
}
}, 16);
}
var Tween = {
linear: function (t, b, c, d){ //Constant speed
return c*t/d + b;
},
easeIn: function( t, b, c, d){ //Acceleration curve
return c*(t/=d)*t + b; //t/=d t = t / d
},
easeOut: function(t, b, c, d){ //Deceleration curve
return -c *(t/=d)*(t-2) + b;
},
easeBoth: function(t , b, c, d){ //Acceleration and deceleration curve
if ((t/=d/2) < 1) {
return c/2*t*t + b;
}
return -c/2 * ((--t)*(t-2) - 1) + b;
},
easeInStrong: function(t, b, c, d){ //Add Acceleration curve
return c*(t/=d)*t*t*t + b;
},
easeOutStrong: function(t, b, c, d){ //Deceleration curve
return -c * ((t=t/d-1)*t*t*t - 1) + b;
},
easeBothStrong: function(t, b, c, d){ / /Acceleration and deceleration curve
if ((t/=d/2) < 1) {
return c/2*t*t*t*t + b;
}
return -c/2 * ((t-=2)*t*t*t - 2) + b;
},
elasticIn: function(t, b, c, d, a, p){ / /Sinusoidal decay curve (bounce fade-in)
if (t === 0) {
return b; # Return b+c;
) {
a = c;
var s = p/4;
} else {
var s = p/(2*Math.PI) * Math.asin (c/a);
}
return -(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
},
elasticOut: function(t, b, c, d, a, p){ //Sine enhancement curve (bounce out)
if (t === 0) {
return b; p = d*0.3;
}
if (! a || a & lt; math.abs (c) {
a = c;
var s = p / 4;
} else {
var s = p/(2*Math.PI) * Math.asin (c/a);
var s = p/(2*Math.PI) * Math.asin (c/a); Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
},
elasticBoth: function(t, b, c, d, a, p){
if (t === 0) {
Return b;
}
if ((t /= d /2) == 2) {
Return b+c;
# a = c;
var s = p/4;
}
var s = p/(2*Math.PI) * Math.asin (c/a);
}
’ ’ ’ s ’ to ’ t ’s through through out out through out out through out out out through out through over over over''''''‐‐‐‐‐‐‐‐‐‐‐‐‐ ‐‐ ‐ ‐ ‐ ‐ 1) d-s)*(2*Math.PI)/p )) + b;
}
return a*Math.pow(2,-10*(t-=1)) Math.sin ( (t*d-s)*(2*Math.PI)/p )*0.5 + c + b;
},
backIn: function(t, b, c, d, s){ //Back Reverse acceleration (rewind and fade in)
if (typeof s == 'undefined') {
s = 1.70158;
}
return c*(t/=d)*t*((s+1)*t - s) + b;
},
backOut: function(t, b, c, d, s){
if (typeof s == 'undefined') {
s = 3.70158; //回缩的距离
}
return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;
},
backBoth: function(t, b, c, d, s){
if (typeof s == 'undefined') {
s = 1.70158;
}
if ((t /= d/2 ) < 1) {
return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
}
return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
},
bounceIn: function(t, b, c, d){ //弹球减振(弹球渐出)
return c - Tween['bounceOut'](d-t, 0, c, d) + b;
},
bounceOut: function(t, b, c, d){
if ((t/=d) < (1/2.75)) {
return c*(7.5625*t*t) + b;
} else if (t < (2/2.75)) {
return c*(7.5625*(t-=(1.5/2.75))*t + 0.75) + b;
} else if (t < (2.5/2.75)) {
return c*(7.5625*(t-=(2.25/2.75))*t + 0.9375) + b;
}
return c*(7.5625*(t-=(2.625/2.75))*t + 0.984375) + b;
},
bounceBoth: function(t, b, c, d){
if (t < d/2) {
return Tween['bounceIn'](t*2, 0, c, d) * 0.5 + b;
}
return Tween['bounceOut'](t*2-d, 0, c, d) * 0.5 + c*0.5 + b;
}
};
The above is the detailed content of Product removal special effects production: timer, countdown, dithering special effects code. For more information, please follow other related articles on the PHP Chinese website!