Monday, 15 July 2013

jquery - How to properly kill a function -



jquery - How to properly kill a function -

i have video player opens , plays whenever link clicked , after 2 videos viewed there form appears allows rate info given.

the problem i'm having there replay button appears when video completed. have settimeout in place away video , it's overlay runs rate form function. if replay button clicked settimeout still running , midway through replay of video function runs. here code:

remove video overlay

fnvideooverlayoff = function () { jquery('#video, #block, .video-closebtn').css('display', 'none'); }

jw player code

jwplayer('videoscreen').setup({ flashplayer: '/assets/js/lib/player.swf', allowscriptaccess: "always", width:972, height:547, controlbar: "none", autostart: true, playlistfile: "/assets/videos/playlist.xml", events: { onplaylistitem: function (event) { jquery(document).idletimer('destroy'); }, onplay: function (event) { }, oncomplete: function (event) { settimeout(function () { fnvideooverlayoff(); }, 10000); var clickcount = 0; if(jquery.cookie('clickcount') == 2) { fnrateoverlayon(); jquery('#video, .video-closebtn').css('display', 'none'); } } } });

i kill fnvideooverlayoff(); if replay button clicked

store reference settimeout, , phone call cleartimeout() when want prevent finishing.

fnvideooverlayofftimer = settimeout(... // , later on when want "kill" it, cleartimeout(fnvideooverlayofftimer);`

ideally declare fnvideooverlayofftimer somewhere maintain off global scope, optional.

jquery function jwplayer die

No comments:

Post a Comment