jQuery delay function on click -
i'm having trouble trying delay function executing on click event.
i have series of links, each one's href
being unique youtube video embed url. i'm trying switch source of iframe on page, using 1 of these youtube urls. i'm trying delay switch while page scrolls top.
i have created fiddle better illustrates point.
i had 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 page , switching iframe, scrolling page while switching iframe source made scroll animation bit jerky isn't ideal.
any great.
thanks in advance.
there's no need mess around setinterval
or settimeout
. the animate
method accepts complete
callback run when animation complete.
$(".play-video").click(function(e) { $("html, body").animate({ scrolltop: 0 }, 500, function() { $("#video-frame").attr("src", $(this).attr("href")); }); });
Comments
Post a Comment