top of page

How to move elements to random positions

PROJECTS USED

Start Now
Start Now
Start Now
Start Now

TAGS

SUITABLE FOR

Editor X, Classic editor

ABOUT

Interested in randomizing animations? Learn how to move elements on your Wix site to random positions.

Layout

01. Add some elements
02. Adjust the position of the elements

Layout

Add paragraph text. Click “Edit Text” to customize this theme across your site. You can update and reuse text themes.

Velo

01. Turn on Dev Mode
02. Paste the code
03. Rename the element IDs (“Shape01”)
04. Adjust X and Y pixel distance
05. Customize the duration and easing

Velo
import wixAnimations from 'wix-animations';


$w.onReady(function () {
randomMove()
});


function randomMove() {
        const shapes = ['#Shape01', '#Shape02'];

        shapes.forEach(shape => {
            $w(shape).onMouseIn(async () => {
                let moveX = await randomInteger(-50, 50);
                let moveY = await randomInteger(-50, 50);

                wixAnimations.timeline()
                    .add($w(shape), { x: moveX, y: moveY, duration: 400, easing: 'easeOutBack' }).play();
            })

        })
    }

function randomInteger(min, max) {
        return Math.floor(Math.random() * (max - min + 1)) + min;
    }

HAVING TROUBLE?

Contact our VIP support channel at vip@support.wix.com and our team will contact you within 24 hours.

MORE HOW TO'S

How to use the Blog API

How to create dynamic lightboxes

How to create hover interactions

How to create a floating image effect

How to create image hover interactions in a list

How to create big buttons

bottom of page