我有这个功能:
var titleLetters = new Array();
var titleLettersShadow = new Array();
titleLetters[0] = $('.title_main:nth-of-type(1)'); titleLettersShadow[0] = $('.title_shadow:nth-of-type(1)');
titleLetters[1] = $('.title_main:nth-of-type(2)'); titleLettersShadow[1] = $('.title_shadow:nth-of-type(2)');
titleLetters[2] = $('.title_main:nth-of-type(3)'); titleLettersShadow[2] = $('.title_shadow:nth-of-type(3)');
titleLetters[3] = $('.title_main:nth-of-type(4)'); titleLettersShadow[3] = $('.title_shadow:nth-of-type(4)');
titleLetters[4] = $('.title_main:nth-of-type(5)'); titleLettersShadow[4] = $('.title_shadow:nth-of-type(5)');
titleLetters[5] = $('.title_main:nth-of-type(7)'); titleLettersShadow[5] = $('.title_shadow:nth-of-type(7)');
titleLetters[6] = $('.title_main:nth-of-type(8)'); titleLettersShadow[6] = $('.title_shadow:nth-of-type(8)');
titleLetters[7] = $('.title_main:nth-of-type(9)'); titleLettersShadow[7] = $('.title_shadow:nth-of-type(9)');
titleLetters[8] = $('.title_main:nth-of-type(10)'); titleLettersShadow[8] = $('.title_shadow:nth-of-type(10)');
titleLetters[9] = $('.title_main:nth-of-type(11)'); titleLettersShadow[9] = $('.title_shadow:nth-of-type(11)');
titleLetters[10] = $('.title_main:nth-of-type(12)'); titleLettersShadow[10] = $('.title_shadow:nth-of-type(12)');
titleLetters[11] = $('.title_main:nth-of-type(13)'); titleLettersShadow[11] = $('.title_shadow:nth-of-type(13)');
titleLetters[12] = $('.title_main:nth-of-type(14)'); titleLettersShadow[12] = $('.title_shadow:nth-of-type(14)');
titleLetters[13] = $('.title_main:nth-of-type(15)'); titleLettersShadow[13] = $('.title_shadow:nth-of-type(15)');
titleLetters[14] = $('.title_main:nth-of-type(16)'); titleLettersShadow[14] = $('.title_shadow:nth-of-type(16)');
function blinkLetter(){
var ott = new Array (0,1,2,3,4,5,6,7,8,9,10,11,12,13,14);
var returnNumber = ott[Math.floor(Math.random()*ott.length)];
var finalLetter1 = titleLetters[returnNumber];
var finalLetter2 = titleLettersShadow[returnNumber];
finalLetter1.css('opacity','.6');
finalLetter2.css('opacity','.6');
setTimeout(function(){
finalLetter1.css('opacity','.9');
finalLetter1.css('opacity','.9');
},Math.floor(Math.random() * (500- 200 + 1)) + 200);
setTimeout(function(){
finalLetter1.css('opacity','.6');
finalLetter2.css('opacity','.6');
},Math.floor(Math.random() * (850- 550 + 1)) + 550);
setTimeout(function(){
finalLetter1.css('opacity','1');
finalLetter2.css('opacity','.4');
var ot2 = new Array (0,1);
if (ot2==0){
setTimeout(function(){
finalLetter1.css('opacity','.1');
finalLetter2.css('opacity','.1');
},Math.floor(Math.random() * (500- 200 + 1)) + 200);
setTimeout(function(){
finalLetter1.css('opacity','1');
finalLetter1.css('opacity','.4');
},Math.floor(Math.random() * (900- 500 + 1)) + 500);
}
},Math.floor(Math.random() * (1400- 1270 + 1)) + 1270);
var randomTimeGen = Math.floor(Math.random() * (2500 - 200 + 1)) + 200;
setTimeout(blinkLetter,randomTimeGen);
}
从它的长度来看,我决定把它放在一个外部的JS文件中,但这样做不起作用。
我尝试了以下内容:
$(function(){});
$(document).ready(function(){});
但那并没有奏效。有什么想法吗?