Javascript淡入文本&;外出-不同的时间
我一直在用这个代码淡入淡出文本。不过,我偶尔会把它用作新闻标题,有些标题会比其他标题长得多,用户需要更多的时间阅读。有没有办法为每次淡入设定不同的时间Javascript淡入文本&;外出-不同的时间,javascript,Javascript,我一直在用这个代码淡入淡出文本。不过,我偶尔会把它用作新闻标题,有些标题会比其他标题长得多,用户需要更多的时间阅读。有没有办法为每次淡入设定不同的时间 <script> var counter = 0; function changeText() { var quotes = new Array(); quotes[0] = "quote1"; quotes[1] = "quote2"; quotes[2] = "quot
<script>
var counter = 0;
function changeText()
{
var quotes = new Array();
quotes[0] = "quote1";
quotes[1] = "quote2";
quotes[2] = "quote3";
quotes[3] = "quote4";
quotes[4] = "quote5";
if (counter > 4)
{
counter = 0;
}
document.getElementById("textslide").innerHTML = quotes[counter];
setTimeout(function(){changeText()},1000);
counter ++;
}
</script>
var计数器=0;
函数changeText()
{
var quotes=新数组();
引号[0]=“引号1”;
引号[1]=“引号2”;
quotes[2]=“quote3”;
引号[3]=“引号4”;
引号[4]=“引号5”;
如果(计数器>4)
{
计数器=0;
}
document.getElementById(“textslide”).innerHTML=quotes[counter];
setTimeout(函数(){changeText()},1000);
计数器++;
}
试试这个():
为什么使用jQuery标记?我看不出“需要更多的时间让用户阅读”——因为你不可能知道用户的阅读速度有多快(或慢),从可用性的角度来看,这通常是个坏主意。
var counter = 0;
function changeText()
{
// Use an array of objects so each quote can have it's own display duration
var quotes = new Array();
quotes[0] = { text: "quote1", time: 500 };
quotes[1] = { text: "quote2", time: 500 };
quotes[2] = { text: "quote3", time: 500 };
quotes[3] = { text: "quote4", time: 500 };
quotes[4] = { text: "much longer quote", time: 2000 };
// get the current quote
var quote = quotes[counter];
document.getElementById("textslide").innerHTML = quote.text;
setTimeout(function(){changeText()}, quote.time);
counter ++;
// You probably want to reset your counter here
if (counter > 4) {
counter = 0;
}
}