订阅按钮动画

订阅按钮动画
下载次数:12 文件大小:3.95KB 所需积分:0 QQ联系购买积分:3331653644(1元=10积分)
var subButton = document.querySelector('.subscribe-button');
var subbedClass = 'subbed';

subButton.addEventListener('click', function(e) {
	toggleSubbed();
	e.preventDefault();
});

function toggleSubbed() {
	var text;
	var count = subButton.dataset.count;
	console.log(count)
		 
	if (subButton.classList.contains(subbedClass)) {
		subButton.classList.remove(subbedClass);
		text = 'Subscribe';
		count--;
	} else {
		subButton.classList.add(subbedClass);
		text = 'Subscribed';
		count++;
	}
	
	subButton.querySelector('.subscribe-text').innerHTML = text;
	subButton.dataset.count = count;
}

if ('alert' == '') {
	window.setInterval(toggleSubbed, 1000);
}

 

0 条评论