我有一個用戶定義的函數,我想延遲它的執行。想要 延遲花式(),我正在使用setTimeout。但它瞬間運行。我也設置了不同的時間延遲 但它不起作用。是否有任何其他方法或我使用它錯了?請幫忙。setTimeout不工作延遲
在此先感謝。 阿里
$('a.vid').click(function(){
setTimeout(fancy(this) ,2000);
});
function fancy(that){
var videoFile = $(that).attr('videofile');
var videoWidth = Number($(that).attr('videowidth'));
var videoHeight =Number($(that).attr('videoheight'));
var videoCode = '<video width="'+videoWidth+'" height="'+videoHeight+'" controls autoplay autobuffer><source src="includes/video/'+videoFile+'.ogv" type="video/ogg" /><source src="includes/video/'+videoFile+'.mp4" type="video/mp4" /><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="'+videoWidth+'" height="'+(videoHeight+40)+'" id="lynda_video_player" align="middle"><param name="allowScriptAccess" value="sameDomain"><param name="allowFullScreen" value="true"><param name="movie" value="lynda_video_player.swf?videoFile=includes/video/'+videoFile+'.mp4&skinFile=lynda_video_skin.swf&videoFileWidth='+videoWidth+'&videoFileHeight='+videoHeight+'"><param name="quality" value="high"><param name="wmode" value="transparent"><param name="scale" value="noscale"><param name="salign" value="lt"><embed src="lynda_video_player.swf?videoFile=includes/video/'+videoFile+'.mp4&skinFile=lynda_video_skin.swf&videoFileWidth='+videoWidth+'&videoFileHeight='+videoHeight+'" quality="high" width="'+videoWidth+'" height="'+(videoHeight+40)+'" name="lynda_video_player" align="middle" allowscriptaccess="sameDomain" type="application/x-shockwave-flash" scale="noscale" salign="lt" wmode="transparent" allowfullscreen="true" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed></object></video>';
$('#videoPlayer').html(videoCode);
$.fancybox({
'transitionIn' : 'fade',
'transitionOut' : 'fade',
'overlayColor' : '#000',
'overlayOpacity' : '.6',
'href' : '#videoPlayer'
});
}
+1歡迎到我們的社會! 2小時內向我們的社區提出2個問題! – 2013-04-07 08:29:56
謝謝。你們是非常有幫助的。 – user2253925 2013-04-07 09:08:55
[爲什麼我使用setTimeout時立即執行該方法?](http://stackoverflow.com/questions/7137401/why-is-the-method-executed-immediately-when-i-use-settimeout) – 2013-04-07 13:07:27