2012-04-18 68 views
0

我試圖顯示和隱藏元素,有點像幻燈片,但我想控制每個單獨的元素顯示多長時間。我不希望元素淡入或淡出,而是在隱藏前一個元素之後立即出現。試着在電視節目或類似的東西之後拍攝片頭,但每個元素都可以單獨計時。我到目前爲止如何才能做到這一點?jQuery的 - 顯示/隱藏元素+控制每個元素的個人時間

(我使用.delay遇到麻煩 - 這不是在做什麼我已經告訴它在JS做)

<html> 
<title>Untitled</title> 
<head> 

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script> 

<script type="text/javascript"> 

$(document).ready(function() { 

    $('#one').delay(1000).show(0, function() { }); 

    $('#one').delay(3000).hide(0, function() { }); 

    $('#two').delay(3000).show(0, function() { }); 

    $('#two').delay(4000).hide(0, function() { }); 

    $('#three').delay(4000).show(0, function() { }); 

    $('#three').delay(6000).hide(0, function() { }); 

    $('#four').delay(6000).show(0, function() { }); 

    $('#four').delay(6000).hide(0, function() { }); 

}); 

</script> 
<style type="text/css" media="screen"> 

    body { 
    margin: 0px; 
    padding: 0px; 
    font-family: arial, sans-serif; 
    padding: 0px; 
    background: #fff; 
    } 

#one, #two, #three, #four, #five, #six { 
    position: absolute; 
    top: 50px; 
    left: 50px; 
    display: none; 
    font-size: 48px; 
    font-weight: bold; 
    font-family: arial, sans-serif; 
    color: #111; 
} 

</style> 
</head> 
<body>    
    <p id="one">this is text #1</p> 
    <p id="two">this is text #2</p> 
    <p id="three">this is text #3</p> 
    <p id="four">this is text #4</p> 
    <p id="five">this is text #5</p> 
    <p id="six">this is text #6</p> 
</body> 
</html> 
+0

工作在哪裏的問題? – gdoron 2012-04-18 03:01:32

回答

1

我在你想正是猜測,但我認爲這是你在找什麼:

$('#one').delay(1000).show(0).delay(1000).hide(0); 
$('#two').delay(2000).show(0).delay(1000).hide(0); 
$('#three').delay(3000).show(0).delay(1000).hide(0); 
$('#four').delay(4000).show(0).delay(1000).hide(0); 
$('#five').delay(5000).show(0).delay(1000).hide(0); 
$('#six').delay(6000).show(0).delay(1000).hide(0); 

你可以看到它在http://jsfiddle.net/3XnGR/