2011-01-18 2 views
0

マウスの移動などのユーザーの操作に応答して機能が開始されるのではなく、自動化されたスクリプトが完了したときに機能を実行する方法はありますか?イベントハンドラの使用

答えて

0

あなたのコードを変更しました。

<font face="helvetica" color="1b1b1b" size="5px" repeat> 

<html> 
<head> 
<style type="text/css"> 
#text-box { 

padding: 4px; 
width: 602px; 
} 
#text-content { 
color: #1b1b1b; 

} 
</style> 

</head> 
<body> 

<div id="text-box"> 
<div id="text-content"></div> 

</div> 
</body> 
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script> 
<script type="text/javascript"> 

$(document).ready(function() { 
var textArray = [ 
'Flow', 
'Precision', 
'Voice', 
'Imagery', 
'Pace', 
'Unity', 
'Word Choice', 
'Rhythm', 
'Inspiration', 
'Balance', 
'Clarity', 
'Simplicity', 
'Revision', 
'Discipline', 
'Fundamentals', 
'Dedication', 
'Practice', 
]; 
$('#text-content').loadText(textArray, 5500); // (array, interval) 
}); 

// custom jquery plugin loadText() 
$.fn.loadText = function(textArray, interval) { 
return this.each(function() { 
var obj = $(this); 
obj.fadeOut('slow', function() { 
obj.empty().html(random_array(textArray)); 
obj.fadeIn('slow'); 
alignarray() 
}); 

timeOut = setTimeout(function(){ obj.loadText(textArray, interval)}, interval); 

}); 
} 
//public function 
function random_array(aArray) { 
var rand = Math.floor(Math.random() * aArray.length + aArray.length); 
var randArray = aArray[ rand - aArray.length ]; 
return randArray; 
} 

function nameoffunction(){ 
    //code in this function will be done after the window loads 
    alert("random_array"); 
} 

function alignarray(){ 
    var alignarray=['left','center','right']; 
    var elem=document.getElementById('text-content'); 
    elem.style.textAlign=alignarray[Math.round(Math.random()*2)]; 
    nameoffunction(); 
} 
</script> 
</html> 
+0

ブレイク - ロック!私はあなたの時間、専門知識、そして礼儀を大いに賞賛します。大切にしてください。 – Mindful

+0

あなたは答えの横のチェックをクリックしてくださいでしょうか? – blake305

+0

回答としてマークされています。遅れて申し訳ありません。 – Mindful

0

スクリプトの最後に関数を呼び出します。 nameoffunction()

+0

Thanks Blake。以下は私が使用している作業コードです。関数ラインをどのように変更しますか: window.onload = function(){ var alignarray = ['left'、 'center'、 'right']; var elem = document.getElementById( 'text-content'); elem.style.textAlign = alignarray [Math.random()* 2)]; }; – Mindful

0
function nameoffunction(){ 
    //code in this function will be done after the window loads 
    alert("hi"); 
} 

window.onload=function(){ 
    var alignarray=['left','center','right']; 
    var elem=document.getElementById('text-content'); 
    elem.style.textAlign=alignarray[Math.round(Math.random()*2)]; 
    nameoffunction(); 
} 
+0

親愛なるブレイク。これに私に固執してくれてありがとう。私はまだスクリプトを動作させていません(ランダムテキストジェネレーターが新しいテキストを挿入したときにテキストを変更する)。ここに私が使用しているコードとのリンクがあります。あなたの追加は最後の2つの段落から成ります。 http://www.creativewritingstudio.com/javascript.html – Mindful

関連する問題