Hello to everyone from the Corvid By Wix community!
I’m a regular user of wix, and now I’m trying to improve my websites with code. I’ve been trying to develop custom animations for buttons, as you can see below.
I got some results with the code below, however, I’m using the same code on every button I put on the page. Is there any way to make a “general code” for these animations?
import { timeline } from 'wix-animations';
$w.onReady(function () {
//Hero Button - Onde Atuamos
const target5 = $w('#bt1');
//Hero Button - Contato
const target4 = $w('#arrow');
const target6 = $w('#btn');
//Learn more Buttons - Saiba Mais
const target1 = $w('#arw1');
const target2 = $w('#arw2');
const target3 = $w('#arw3');
//Hero Button - Onde Atuamos
$w('#bt1').onMouseIn(() => {
timeline()
.add(target5, { y: -5, x: 0, scale: 1, duration: 600, easing: 'easeOutCirc' }, 0)
.play();
})
//Hero Button - Onde Atuamos
$w('#bt1').onMouseOut(() => {
const reset = { y: 0, x: 0, scale: 1, duration: 600, easing: 'easeOutCirc' };
timeline()
.add(target5, reset, 0)
.play();
})
//Hero Button - Contato
$w('#btn1').onMouseIn(() => {
timeline()
.add(target4, { y: 0, x: 5, scale: 1, duration: 600, easing: 'easeOutCirc' }, 0)
.add(target6, { y: -5, x: 0, scale: 1, duration: 600, easing: 'easeOutCirc' }, 0)
.play();
})
//Hero Button - Contato
$w('#btn1').onMouseOut(() => {
const reset = { y: 0, x: 0, scale: 1, duration: 600, easing: 'easeOutCirc' };
timeline()
.add(target4, reset, 0)
.add(target6, reset, 0)
.play();
})
P.S.: I’m not a coder, just trying to do something.
Thank you all for the attention!