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

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

wso2esb - How to concatenate JSON array values in WSO2 ESB? -