Skip to content

Instantly share code, notes, and snippets.

@HamedFathi
Last active June 17, 2020 17:27
Show Gist options
  • Save HamedFathi/a6b2ae6b0baa898ecf93e48fb7cdb7d0 to your computer and use it in GitHub Desktop.
Save HamedFathi/a6b2ae6b0baa898ecf93e48fb7cdb7d0 to your computer and use it in GitHub Desktop.
ripple-au2
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Dumber Gist</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0, user-scalable=no">
<base href="/">
</head>
<!--
Dumber Gist uses dumber bundler, the default bundle file
is /dist/entry-bundle.js.
The starting module is pointed to "main" (data-main attribute on script)
which is your src/main.ts.
-->
<body>
<my-app></my-app>
<script src="/dist/entry-bundle.js" data-main="main"></script>
</body>
</html>
{
"dependencies": {
"aurelia": "dev"
}
}
import Aurelia from 'aurelia';
import { MyApp } from './my-app';
import { RippleCustomAttribute } from './ripple';
Aurelia.register(RippleCustomAttribute).app(MyApp).start();
.button {
background-color: #4CAF50;
border: none;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
cursor: pointer;
}
<!--
Try to create a paired css/scss/sass/less file like my-app.scss.
It will be automatically imported based on convention.
-->
<!--
There is no bundler config you can change in Dumber Gist to
turn on shadow DOM.
But you can turn shadow DOM on by adding a meta tag in every
html template:
<use-shadow-dom>
-->
<button at-ripple class="button">Button</button>
export class MyApp {
}
[data-animation] {
position: relative;
overflow: hidden;
}
.ripple {
width: 2px;
height: 2px;
position: absolute;
border-radius: 50%;
background-color: rgba(255, 255, 255, 0.5);
-webkit-animation: rippleEffect 0.5s ease-in-out;
animation: rippleEffect 0.5s ease-in-out;
}
@-webkit-keyframes rippleEffect {
0% {
-webkit-transform: scale(1);
transform: scale(1);
}
100% {
opacity: 0;
-webkit-transform: scale(var(--scale));
transform: scale(var(--scale));
}
}
@keyframes rippleEffect {
0% {
-webkit-transform: scale(1);
transform: scale(1);
}
100% {
opacity: 0;
-webkit-transform: scale(var(--scale));
transform: scale(var(--scale));
}
}
import { customAttribute, inject } from "aurelia";
import * as cssRipple from './at-ripple.css'
@customAttribute({ name: 'at-ripple'})
@inject(Element)
export class RippleCustomAttribute {
constructor(private element: Element) {
cssRipple;
}
afterAttach() {
let htmlElement = this.element as HTMLElement;
htmlElement.setAttribute('data-animation', 'ripple');
htmlElement.addEventListener('mousedown', function (e) {
const x = e.pageX - this.offsetLeft;
const y = e.pageY - this.offsetTop;
const w = this.offsetWidth.toString();
const ripple = document.createElement('span');
ripple.className = 'ripple';
ripple.style.left = x + 'px';
ripple.style.top = y + 'px';
ripple.style.setProperty('--scale', w);
this.appendChild(ripple);
setTimeout(() => {
ripple.remove();
}, 500);
})
}
}
export * from './at-ripple';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment