I’m using the following jQuery code to shuffle the video links on the left side of this website
$(document).on("click", ".cboxVideo",
function() {
var elementURL = $("a", this).attr("href");
$(this).colorbox({iframe: true, href: elementURL, innerWidth: 645, innerHeight: 509});
});
$("#videoFront").addClass("cboxVideo");
$("#videoFront").hover(
function() {
$(".playVideo", this).fadeTo(300, 1);
}, function() {
$(".playVideo", this).fadeTo(300, 0.35);
});
$("#videoFront").click(
function(event) {
if($(this).hasClass("cboxVideo")) { event.preventDefault(); }
else {
event.preventDefault();
// Move behind UP and infront DOWN
$(this).animate({top: 155}, 300,
function() {
$(this).css("z-index", "20");
});
$("#videoBack").animate({top: -95}, 300,
function() {
$("#videoBack").css("z-index", "10");
});
// Move behind DOWN and infront UP
$(this).animate({top: 62}, 300);
$("#videoBack").animate({top: -3}, 300);
$("#videoBack").removeClass("cboxVideo");
$(this).addClass("cboxVideo");
}
});
$("#videoBack").hover(
function() {
$(".playVideo", this).fadeTo(300, 1);
}, function() {
$(".playVideo", this).fadeTo(300, 0.35);
});
$("#videoBack").click(
function(event) {
if($(this).hasClass("cboxVideo")) { event.preventDefault(); }
else {
event.preventDefault();
// Move behind UP and infront DOWN
$(this).animate({top: -95}, 300,
function() {
$(this).css("z-index", "20");
});
$("#videoFront").animate({top: 155}, 300,
function() {
$("#videoFront").css("z-index", "10");
});
// Move behind DOWN and infront UP
$(this).animate({top: -3}, 300);
$("#videoFront").animate({top: 62}, 300);
$("#videoFront").removeClass("cboxVideo");
$(this).addClass("cboxVideo");
}
});
So, if you click on the video that is in the back, it goes to the front. Then if you click the video that is in the front, it opens a popup div containing the video.
I’m using colorbox for the popup and the video is embedded from YouTube.
The problem is this.
Once I’ve clicked on the video that is in the front and the colorbox function has fired, it totally neglects my if else statement for future clicks. So if I click the 2nd video (that’s currently in the back) so that it goes to the front, and the one I just watched goes to the back, Even though the video is now in the back, when I click it again, the colorbox plugin fires -.-
How do I solve that?
Managed to solve this one myself, but thank you guys for trying 🙂
Got it to work by replacing the following line
with