Jump to content

How can i put a delay on a function so it doesn't show my images until a certain time passes

Recommended Posts

Hi!

 

In the homepage of my website www.diegphoto.com, I have code to autoplay portfolio categories. The problem is that the image of the first category is not displayed since the function is executed before the page loads. I would like to set a timeout, or a code so that it does not autoplay until the images are loaded.

My site is diegphoto.com and the password is Asturias

This is the code:

<!--beyondspace autoplay Hover Portfolio start-->
<script>
  (function(){
    window.addEventListener('load', () => {
      beyAutoPlayPortfolio(4000); // change the speed of transition
    });
  })()
  function beyAutoPlayPortfolio(e){let t=document.querySelectorAll(".portfolio-hover-items-list > li");if(t.length>1){let o=new Event("mouseenter"),l=null,r=function(){let i=document.querySelector('.portfolio-hover-item[data-active="true"]').closest("li").nextElementSibling;i||(i=t[0]),i.querySelector("a").dispatchEvent(o),l=setTimeout(r,e)};r(),t.forEach(e=>{e.querySelector("a").addEventListener("mouseenter",function(e){e.isTrusted&&clearTimeout(l)}),e.querySelector("a").addEventListener("mouseleave",function(e){e.isTrusted&&r()})})}}
</script>
<!--beyondspace autoplay Hover Portfolio end-->

 

 

Thank you in advance!

Edited by diegphoto
Link to comment
  • Replies 3
  • Views 337
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

5 hours ago, diegphoto said:

I would like to set a timeout, or a code so that it does not autoplay until the images are loaded.

When you say loaded do you mean visible in the viewport of your browser?

If yes it is possible to write code that won't activate until the images are in the viewport. I know of no such code to handle your specific issue.

Find my contributions useful? Please like, upvote, mark my answer as the best ( solution ), and see my profile. Thanks for your support! I am a Squarespace ( and other technological things ) consultant open for new projects.

Link to comment
1 hour ago, creedon said:

When you say loaded do you mean visible in the viewport of your browser?

If yes it is possible to write code that won't activate until the images are in the viewport. I know of no such code to handle your specific issue.

Hi! Yes, I mean visible for the visitors of the page. Right now the first image changes before being seen. 

Link to comment

It would probably be best if the feature you need was integrated into the code you have. I suggest contacting the author to see if that is something they are willing to add. I doesn't hurt to ask.

Find my contributions useful? Please like, upvote, mark my answer as the best ( solution ), and see my profile. Thanks for your support! I am a Squarespace ( and other technological things ) consultant open for new projects.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment


×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.