henrygd / bigpicture

Lightweight JavaScript image / video viewer. Supports Youtube, Vimeo, etc.
https://henrygd.me/bigpicture
MIT License
818 stars 76 forks source link

Separate scripts for video demos #50

Closed creativeDM closed 3 years ago

creativeDM commented 4 years ago

He mate, i love the script. but how i add to a Html, Youtube, Vimeo video on a button click???? i trying and final result showing repeated - Error: The requested image could not be loaded. why this message showing when i trying to get video on popup window??? i guess i miss something but didn't get the actual issue.... Please help with a little but separate code for lightbox video player?? any feedback would be great..

henrygd commented 4 years ago

I'd be happy to help you figure it out. Can you post a snippet of your code, or make an example on codepen or codesandbox?

creativeDM commented 4 years ago

I'd be happy to help you figure it out. Can you post a snippet of your code, or make an example on codepen or codesandbox?

Here is link of code - https://codesandbox.io/s/bigpicturejs-demos-utx4u?file=/index.html I tried this one with youtube-video this running well at first view, but after i add svg icon to the button, after refresh it didn't work again and showing the same issue - Error: The requested image could not be loaded.

Thanks for your time. and Thanks too for awesome & cool lightbox plugin.. Keep it up..

I also love your another script side-panel like thing. really cool and lightweight, will use it also in near future..

Keep it on brother. but make it little easier to get done with demos for average JS users like me

henrygd commented 3 years ago

No problem! You can make it work by changing e.target to e.currentTarget like this:

BigPicture({
  el: e.currentTarget,
  ytSrc: e.currentTarget.getAttribute("ytSrc")
});

After you put the svg inside the button, e.target becomes the svg when it's clicked (it's the element you clicked to trigger the event). e.currentTarget is always the button even when an element inside is clicked (because it's what you assigned the event listener to). It was failing because the svg does not have the ytSrc attribute.

Here's the working code: https://codesandbox.io/s/bigpicturejs-demos-forked-mwvtq?file=/index.html:3391-3525

I'm going to close this issue, but feel free to follow up with any question or comment.