1 Regarding to the JQuery Slider Tut Mon Dec 27, 2010 1:51 am
Guest
Guest
Regarding to that tutorial i have to say you can use a much more simple JQuery code for the effect.
instead of using
you can use:
and the html:
instead of using
- Code:
<script type="text/javascript">
var gc_slideSpeed = 15 // Higher value = faster
var gc_timer = 10; // Lower value = faster
var objectIdToSlideDown = false;
var gc_activeId = false;
var gc_slideInProgress = false;
function showHideContent(e,inputId)
{
if(gc_slideInProgress)return;
gc_slideInProgress = true;
if(!inputId)inputId = this.id;
inputId = inputId + '';
var numericId = inputId.replace(/[^0-9]/g,'');
var answerDiv = document.getElementById('gc_a' + numericId);
objectIdToSlideDown = false;
if(!answerDiv.style.display || answerDiv.style.display=='none'){
if(gc_activeId && gc_activeId!=numericId){
objectIdToSlideDown = numericId;
slideContent(gc_activeId,(gc_slideSpeed*-1));
}else{
answerDiv.style.display='block';
answerDiv.style.visibility = 'visible';
slideContent(numericId,gc_slideSpeed);
}
}else{
slideContent(numericId,(gc_slideSpeed*-1));
gc_activeId = false;
}
}
function slideContent(inputId,direction)
{
var obj =document.getElementById('gc_a' + inputId);
var contentObj = document.getElementById('gc_ac' + inputId);
height = obj.clientHeight;
if(height==0)height = obj.offsetHeight;
height = height + direction;
rerunFunction = true;
if(height>contentObj.offsetHeight){
height = contentObj.offsetHeight;
rerunFunction = false;
}
if(height<=1){
height = 1;
rerunFunction = false;
}
obj.style.height = height + 'px';
var topPos = height - contentObj.offsetHeight;
if(topPos>0)topPos=0;
contentObj.style.top = topPos + 'px';
if(rerunFunction){
setTimeout('slideContent(' + inputId + ',' + direction + ')',gc_timer);
}else{
if(height<=1){
obj.style.display='none';
if(objectIdToSlideDown && objectIdToSlideDown!=inputId){
document.getElementById('gc_a' + objectIdToSlideDown).style.display='block';
document.getElementById('gc_a' + objectIdToSlideDown).style.visibility='visible';
slideContent(objectIdToSlideDown,gc_slideSpeed);
}else{
gc_slideInProgress = false;
}
}else{
gc_activeId = inputId;
gc_slideInProgress = false;
}
}
}
function initShowHideDivs()
{
var divs = document.getElementsByTagName('DIV');
var divCounter = 1;
for(var no=0;no<divs.length;no++){
if(divs[no].className=='gc_question'){
divs[no].onclick = showHideContent;
divs[no].id = 'gc_q'+divCounter;
var answer = divs[no].nextSibling;
while(answer && answer.tagName!='DIV'){
answer = answer.nextSibling;
}
answer.id = 'gc_a'+divCounter;
contentDiv = answer.getElementsByTagName('DIV')[0];
contentDiv.style.top = 0 - contentDiv.offsetHeight + 'px';
contentDiv.className='gc_answer_content';
contentDiv.id = 'gc_ac' + divCounter;
answer.style.display='none';
answer.style.height='1px';
divCounter++;
}
}
}
window.onload = initShowHideDivs;
</script>
you can use:
- Code:
<script src="http://code.jquery.com/jquery-1.4.4.js"></script>
<script>
$("#button").click(function ()
{ $("#box").slideToggle("slow"); });
</script>
and the html:
- Code:
<div id="button">Click</div>
<div id="box">Wabadabadoo!</div>