商品 | 价格 | 图片 |
---|
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>