question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

loaded event gets triggered multiple times

See original GitHub issue

Hi,

I have multiple lazy images on my page and I want to add a blur effect until they are completely loaded. (showing a blurry low-quality image in the meantime)

It seemed pretty easy working with the property “lazy=loaded” in the css. But I saw that this gets already set when the loading-pic has finished loading.

Then I wanted to solve it with the provided event-listeners. But it seems that those “loaded” events get triggered multple times.

When there is only 1 image on the page I get it 3 times: 1 time for the loading-image and 2 times for the full-sized image.

When there are many images on the page, I get a “loaded” for every image as soon as the first “loaded”-event appears.

Any idea what’s wrong? Or any experience how to solve this?

My code looks somehow like this:

<img v-lazy="getLazyObj(size)" ref="image"  />
// ...
getLazyObj(bp: string) {
  return {
    src: this.getSrc(bp), // returns high quality source
    loading: this.getPreviewSrc(bp), // returns low quality source
  };
}
// ...
mounted() {
  (this as any).$Lazyload.$on('loaded', (evt, fromCache) => {
    if (evt.el === this.$refs.image[0]) {
      console.log(evt); // gets logged at least 3 times
    }
  })
}
img[lazy=loading] {
  filter: blur(20px);
}

PS: the full-sized image also gets requested twice.

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:11

github_iconTop GitHub Comments

3reactions
chrismadrigalcommented, Aug 24, 2018

Experiencing the same exact issue, any solutions?

2reactions
libinvbabucommented, May 22, 2019

Having the same issue. Full-sized image is loading twice. Any solutions??

Read more comments on GitHub >

github_iconTop Results From Across the Web

Event handler being triggered multiple times - Stack Overflow
You are calling addEventListener every time you select a difficultyButton . This means that each time you click a button, you'll be adding ......
Read more >
Page Load called multiple times while loading a Modal - MSDN
The Page_Load event loads once each time the page is requested or if the Page_Load event is wired up twice. Most likely you...
Read more >
Window: load event - Web APIs - MDN Web Docs - Mozilla
The load event is fired when the whole page has loaded, including all dependent resources such as stylesheets, scripts, iframes, and images.
Read more >
ethers.js - Event listener firing multiple times
jsx file, I've set up a websocket and listeners for our 4 events. However, when one of these events fires, it logs in...
Read more >
.on() | jQuery API Documentation
Description: Attach an event handler function for one or more events to the ... The handler is called every time an event occurs...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found