jquery - How can I create filters for embedded videos? -
i want create nav link when clicked, filters videos on page tagged data filter. can done html? need jquery?
<ul class="nav navbar-nav navbar-left"> <li><a href="#" data-filter="video1" tabindex="-1">video 2</a></li> <li><a href="#" data-filter="video2" tabindex="-1">video 1</a></li> </ul> <div class="col-lg-4 col-md-6 col-sm-6 col-xs-12"> <h4>video 2 title</h4> <div class="embed-responsive embed-responsive-16by9" data-filter="video2"> <iframe class="embed-responsive-item" src="video2" frameborder="0" scrolling="no" allowtransparency="true" allowfullscreen></iframe> </div> </div> <div class="col-lg-4 col-md-6 col-sm-6 col-xs-12"> <h4>video 1 title</h4> <div class="embed-responsive embed-responsive-16by9" data-filter="video1"> <iframe class="embed-responsive-item" src="video1" frameborder="0" scrolling="no" allowtransparency="true" allowfullscreen></iframe> </div> </div>
you need kind of javascript if want manipulate visible user.
its easy use id , class values simplify things.
<div class="col-lg-4 col-md-6 col-sm-6 col-xs-12 video video2"> <h4>video 2 title</h4> <div class="embed-responsive embed-responsive-16by9" > <iframe class="embed-responsive-item" src="video2" frameborder="0" scrolling="no" allowtransparency="true" allowfullscreen></iframe> </div> </div> then can use
<ul class="nav navbar-nav navbar-left"> <li><a href="#" id="video1" class="videofilterbtn" tabindex="-1">video 2</a></li> <li><a href="#" id="video2" class="videofilterbtn" tabindex="-1">video 1</a></li> </ul> and script be
$( document ).ready(function() { $(".videofilterbtn").on("click", function(e){ e.preventdefault() // stop default click events navigation $(".video").hide() // hide videos $("#" + $(this).prop("id")).show() // show 1 class matching element id } }); what have done add 2 classes top level div wrapping video iframes. 1 generic 'video' class used hide videos, , other matches video number had in data-filter such 'video2'.
i added id attribute each of elements, , class hook them click event.
the script says:
- find elements class = videofilterbtn
- attach them click event will
- stop default browser click behaviour;
- hide elements 'video' class (and children)
- show elements class matching clicked elements id value.
if want sexier effects change .hide() .fadeout() , .show() .fadein().
you need link jquery.
ps. might want consider using object instead of iframes host videos.
Comments
Post a Comment