October 9, 201511 yr Hello, I have an ecommerce site. I am trying to do as the title says – display a small thumbnail which opens out into a larger video. My knowledge of web design is basic. I use an ecommerce platform for my site (ekmpowershop). Example: the video on this site under ‘Latest Video’ http://www.prestfelde.co.uk/current-information How would I achieve this? Any advice would be greatly appreciated. Thanks Dan
October 9, 201511 yr Welcome to the forums That's done with a "Lightbox". See Youtube demo at http://fancyapps.com/fancybox/
October 9, 201511 yr I have done this numerous times just using JavaScript and data attributes. You put the url of a video on a data-attribute say on a link for it. In your JavaScript you get that data attribute and put that in the src attribute of an iframe inside of your lightbox / modal. There's numerous ways to do this, but this is a pretty easy easy way to do so.
October 10, 201511 yr As Robert said, use data attributes. I see the website you used as an example uses Bootstrap, does yours by any chance? Bootstrap has modals built in, but I wouldn't recommend adding Bootstrap just for the modals - though you can compile what features you want here: http://getbootstrap.com/customize/ Lets say for arguments sake you are using Bootstrap (please don't flame me, Bootstrap haters), something like the following; <a href="http://youtube.com/videoid" data-target="#videomodal" data-toggle="modal" class="video-thumbnail"><img src="thumbnail.png" alt="Please use alt tags, please" title="My super cool video"/></a> The href above is the video link, and the data-target is the id of the modal that will be opened on click. Then your modal html: <div class="modal fade" id="videomodal" role="dialog" aria-hidden="true"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> <h4 class="modal-title">Video</h4> </div> <div class="modal-body"> <iframe id="video-full"></iframe> </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> </div> </div> </div> </div> You'll see there's an empty iframe in the modal-body, that's where we'll be placing the source when the links are clicked. Then the magic: <script> $('.video-thumbnail').click(function(e) { $('#videomodal #video-full').attr('src', $(this).attr('href')); }); </script> When the video thumbnail link is clicked, it's href is copied to the iframes source. The above is based on Bootstrap, but can easily be modified for other lightbox/modal solutions. If you need any further instructions I'm only a pm away. Obviously this is very basic, you'd need to style the iframe for better fitting and the thumbnail images. I've used similar methods on many websites. There might be better ways to do this; but this makes sense in my current state of mind, I'm probably not the only sleep deprived person lurking these forums Goodluck! Edited October 10, 201511 yr by EddieT
October 10, 201511 yr Here you go. http://jsfiddle.net/sm1quLyb/1/ That's with the above code, and a minute amount of styling. Edit: I got bored and added a couple more styles: http://jsfiddle.net/sm1quLyb/2/ Edit 3: To show you how you can manipulate data attributes I've now added titles as data-titles to the hrefs, and the updated code changes the title each time you click a link, also, closing the modal now clears the iframe to stop that annoying millisecond previous video displaying. http://jsfiddle.net/sm1quLyb/3/ Edited October 10, 201511 yr by EddieT
Create an account or sign in to comment