html5 渐变动画效果图,HTML5 CSS3很棒的一款带渐变背景色和涟漪动画的原质化风格按钮...

JavaScript

语言:

JaveScriptBabelCoffeeScript

确定

const isMobile = window.navigator.userAgent.match(/Mobile/) && window.navigator.userAgent.match(/Mobile/)[0] === "Mobile";

const event = isMobile ? "touchend" : "click";

const button = document.querySelectorAll('*[data-animation="ripple"]'),

container = document.querySelector(".container");

for (var i = 0; i < button.length; i++) {

const currentBtn = button[i];

currentBtn.addEventListener(event, function(e) {

e.preventDefault();

const button = e.target,

rect = button.getBoundingClientRect(),

originalBtn = this,

btnHeight = rect.height,

btnWidth = rect.width;

let posMouseX = 0,

posMouseY = 0;

if (isMobile) {

posMouseX = e.changedTouches[0].pageX - rect.left;

posMouseY = e.changedTouches[0].pageY - rect.top;

} else {

posMouseX = e.pageX - rect.left;

posMouseY = e.pageY - rect.top;

}

const baseCSS = `position: absolute;

width: ${btnWidth * 2}px;

height: ${btnWidth * 2}px;

transition: all linear 700ms;

transition-timing-function:cubic-bezier(0.250, 0.460, 0.450, 0.940);

border-radius: 50%;

background: var(--color-ripple);

top:${posMouseY - btnWidth}px;

left:${posMouseX - btnWidth}px;

pointer-events: none;

transform:scale(0)`

var rippleEffect = document.createElement("span");

rippleEffect.style.cssText = baseCSS;

//prepare the dom

currentBtn.style.overflow = "hidden";

this.appendChild(rippleEffect);

//start animation

setTimeout(function() {

rippleEffect.style.cssText = baseCSS + `transform:scale(1); opacity: 0;`;

}, 5);

setTimeout(function() {

rippleEffect.remove();

//window.location.href = currentBtn.href;

}, 700);

})

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值