I'm having some trouble trying to delay a function from executing on a click event.
I have a series of links, each one's href being a unique YouTube video embed URL. What I'm trying to do is switch the source of an iframe on my page, using one of these YouTube URLs. But I'm trying to delay the switch while my page scrolls back to the top.
I have created a Fiddle that better illustrates my point.
I originally had this JS function;
$(".play-video").click(function(e) {
$("html, body").animate({ scrollTop: 0 }, 500);
$("#video-frame").attr("src", $(this).attr("href"));
});
Which worked in both scrolling the page and switching the iframe, but scrolling the page while switching the iframe source made the scroll animation a bit jerky which isn't ideal.
Any help with this would be great.
Thanks in advance.
completefunction to jquery's animate, which will only run once the animation is complete