Do you want the time to be recorded as soon as the element starts fading in or when the fade is done?
In the first case, just run those two lines together:
$('#stimuli').text('A WORD').fadeIn().delay(displayTime).fadeOut();
t1 = (new Date).getTime();
fadeIn
, delay
, and fadeOut
run asynchronously, so the second line actually happens before the other methods.
To record the time after the fade is done, you need a callback:
$('#stimuli')
.text('A WORD')
.fadeIn(function () {
t1 = (new Date).getTime();
})
.delay(displayTime)
.fadeOut();