Hide element after X seconds

Hello,
I want to hide an image 6 seconds after page load
Is that possible. What would be the correct code? This are my best efforts with no luck:

import wixWindow from 'wix-window';
const image6 = $w('image6')

$w.onReady(function () {
    setTimeout(image6.hide, 6000)
});

or

import wixWindow from 'wix-window';
const image6 = $w('image6')

export function image6_viewportEnter(event) {
    setTimeout(image6.hide, 6000) 
}

Hi Philippe

You cannot assign $w(‘#image6’) to a const outside of the $w.onReady() function.

$w(‘#image6’) most likely doesn’t exist at this point. Make the image6 a let and assign it in the onReady or just use $w(‘#image6’) without assigning to to anything :wink:

1 Like

If you share your page URL one of us in the community will be able to address your problem.

you could use $w(“#image6”).hide and set a “delay” or 6000

Great Thanks Man!

your welcome bro!

Check our Forum Guidelines .

Search Before Posting. Use the Forum search. There’s a great chance that someone has already solved the problem that you are facing. If you post a question that has already been asked and answered, your post may be locked. You might find the answer to your question by searching the Corvid documentation.

This post is being closed as it was from 2018 and if you had searched the forum for previous other posts on delaying an element, then you would have found many that would have helped you like this one from August 2017.
https://www.wix.com/corvid/forum/community-discussion/adding-a-delay

In order to add a delay, you should use the javascript setTimeout function. There are a lot of examples on the web how to do so.

For your case

$w.onReady(function() {
  setTimeout(function() {
    $w("#image11").show("FadeIn"); 
  }, 1000);
}

Or you could have looked at the hide function within the Wix API Reference itself.

1 Like