Skip to content

Instantly share code, notes, and snippets.

@AnatoliyAkhmatov
Created May 22, 2021 05:14
Show Gist options
  • Save AnatoliyAkhmatov/839f83d12762baf9a05e6dd19d21467b to your computer and use it in GitHub Desktop.
Save AnatoliyAkhmatov/839f83d12762baf9a05e6dd19d21467b to your computer and use it in GitHub Desktop.
.t-btn
position: relative
overflow: hidden
padding: 20px
background: #fff
display: inline-block
.bg
position: absolute
background: red
size: 0
background: #000
transition: width 400ms, height 400ms
will-transform: width
transform: translate(-50%, -50%)
border-radius: 50%
pointer-events: none
span:not(.bg)
z-index: 2
position: relative
&.hover
color: #fff
.bg
size: 30vw
export default class Button {
constructor(app) {
app.on('init', () => {
this.init()
})
}
init() {
x('.t-btn').forEach(el => {
$(el).hover((e) => {
e = e.originalEvent
let bg = x(el).x('.bg')
if (bg.length != 0) {
let bCoods = el.getBoundingClientRect()
let x = e.clientX - bCoods.x
let y = e.clientY - bCoods.y
bg.style.top = y + 'px'
bg.style.left = x + 'px'
}
setTimeout(() => { el.addClass('hover') }, 50)
}, () => {
el.removeClass('hover')
})
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment