I want to change the placement of one of my images based on a number which is subjected to change from time to time. I thought I’ll use javascript to do this.
I have a public/animate.js file which contains the following:
export function asteroidMove(asteroid) {
var elem = asteroid;
elem.style.position= ‘absolute’;
elem.style.top = ‘490px’;
elem.style.left = ‘200px’;
elem.style.visibility=‘visible’;
return ‘test’;
}
and in my page code i have,
import {asteroidMove} from ‘public/animate.js’;
…
console.log(asteroidMove($w(‘#image6’)));
// image 6 is the image I want to change the placement.
But this coesn’t work. No errors are reported (But the image doesn’t appear in the correct place and console doesn’t log ‘test’). Any help is much appreciated. I am not an expert on Javascript, so learning as I go.
Currently, Wix Code does not expose an API for moving elements on the page. Sometimes you can work around this problem by having multiple elements that you show and hide (or expand and collapse) based on some criteria.
I too have this need right now. I wanted to have 4 buttons next to one another, where each is clicked and a new set of buttons is loaded as sub-categories with the remaining original buttons either moving and resizing away (which is apparently totally impossible at this time) or at least hiding or collapsing the parent set of buttons BUT THE PARENT and move the parent to focus area, then expanding the sub category buttons around it if you will… but the only way I can do this is custom code in an iframe which is highly not ideal in general for too many reasons to list.