1秒ごとにhtmlのいくつかの要素を隠して見たいと思っています。私はJavaScriptでこのコードを持っています。hello() は、メインの html から onload で呼び出されます。そして、関数 go が呼び出されてタイマーを開始します! 1秒ごとに表示される内容が変わると思います。
function hello() {
myTimer();
}
var indexx = 0;
function myTimer(){
var myVar1=setInterval(function(){go1()},1000);
}
function go1()
{
if(indexx==0)
{
var results = document.getElementById("water_2_5");
results.setAttributeNS(null,"visibility","hidden");
var results = document.getElementById("water_2_1");
results.setAttributeNS(null,"visibility","visible");
indexx+=1;
} else
if(indexx==1)
{
results = document.getElementById("water_2_1");
results.setAttributeNS(null,"visibility","hidden");
//
var results = document.getElementById("water_2_7");
results.setAttributeNS(null,"visibility","visible");
indexx+=1;
}
if(indexx==2)
{
results = document.getElementById("water_2_7");
results.setAttributeNS(null,"visibility","hidden");
//
var results = document.getElementById("water_2_6");
results.setAttributeNS(null,"visibility","visible");
indexx+=1;
}
if(indexx==3)
{
results = document.getElementById("water_2_6");
results.setAttributeNS(null,"visibility","hidden");
//
var results = document.getElementById("water_2_5");
results.setAttributeNS(null,"visibility","visible");
indexx=0;
}
}
でもそれは私にしか見せない、最初と最後の部分?誰かがそれを達成する方法を教えてもらえますか?
答えは:
function hello() {
myTimer();
}
var indexx = 0;
function myTimer(){
var myVar1=setInterval(function(){go1()},1000);
}
function go1()
{
if(indexx==0)
{
var results = document.getElementById("water_2_5");
results.setAttributeNS(null,"visibility","hidden");
var results = document.getElementById("water_2_1");
results.setAttributeNS(null,"visibility","visible");
indexx+=1;
} else
if(indexx==1)
{
results = document.getElementById("water_2_1");
results.setAttributeNS(null,"visibility","hidden");
//
var results = document.getElementById("water_2_7");
results.setAttributeNS(null,"visibility","visible");
indexx+=1;
} else
if(indexx==2)
{
results = document.getElementById("water_2_7");
results.setAttributeNS(null,"visibility","hidden");
//
var results = document.getElementById("water_2_6");
results.setAttributeNS(null,"visibility","visible");
indexx+=1;
}else
{
results = document.getElementById("water_2_6");
results.setAttributeNS(null,"visibility","hidden");
//
var results = document.getElementById("water_2_5");
results.setAttributeNS(null,"visibility","visible");
indexx=0;
}
}