ページに移動して、アコーディオン js 構造の 3 つのコンテンツ コンテナーのいずれかでコンテンツを開くことができるようにしたいと考えています。
html は次のとおりです。
<div id="navigation">
<div id="AccordionContainer" class="AccordionContainer">
<div onclick="runAccordion(1); ContentHeight=1040;" id="reel">
<div class="AccordionTitle" onselectstart="return false;">REEL</div>
</div>
<div id="Accordion1Content" class="AccordionContent">
<div id="reelSpots">
content
</div>
</div>
<div onclick="runAccordion(2); ContentHeight=1075;">
<div class="AccordionTitle" onselectstart="return false;">ABOUT</div>
</div>
<div id="Accordion2Content" class="AccordionContent">
content
</div>
<div onclick="runAccordion(3); ContentHeight=175;">
<div class="AccordionTitle" onselectstart="return false;">CONTACT</div>
</div>
<div id="Accordion3Content" class="AccordionContent">
content
</div>
</div>
</div>
そして、ここに私のjavascriptがあります:
// JavaScript Document
var ContentHeight = 200;
var TimeToSlide = 250.0;
var openAccordion = '';
function runAccordion(index)
{
var nID = "Accordion" + index + "Content";
if(openAccordion == nID)
nID = '';
setTimeout("animate(" + new Date().getTime() + "," + TimeToSlide + ",'"
+ openAccordion + "','" + nID + "')", 33);
openAccordion = nID;
}
function animate(lastTick, timeLeft, closingId, openingId)
{
var curTick = new Date().getTime();
var elapsedTicks = curTick - lastTick;
var opening = (openingId == '') ? null : document.getElementById(openingId);
var closing = (closingId == '') ? null : document.getElementById(closingId);
if(timeLeft <= elapsedTicks)
{
if(opening != null)
opening.style.height = ContentHeight + 'px';
if(closing != null)
{
closing.style.display = 'none';
closing.style.height = '0px';
}
return;
}
timeLeft -= elapsedTicks;
var newClosedHeight = Math.round((timeLeft/TimeToSlide) * ContentHeight);
if(opening != null)
{
if(opening.style.display != 'block')
opening.style.display = 'block';
opening.style.height = (ContentHeight - newClosedHeight) + 'px';
}
if(closing != null)
closing.style.height = newClosedHeight + 'px';
setTimeout("animate(" + curTick + "," + timeLeft + ",'"
+ closingId + "','" + openingId + "')", 33);
}
URL 文字列に #reel を挿入して、Accordion1Content に移動して開くことができるようにしたいと考えています。