WebArtz - The Web Design Forum
Welcome to WebArtz, Guest!

WebArtz is a nice place for discussions related to web designing and coding. We help our members to code their own website templates with HTML and CSS. We give them advice on various issues.

To know more about WebArtz Forum, visit the About Us page.

At the moment, you are viewing the forum as a guest. As a guest you can't make post and participate in discussions. You need to register and become a member of the forum. Click the register link below and become a part of this forum.

Thank You

WebArtz - The Web Design Forum
Welcome to WebArtz, Guest!

WebArtz is a nice place for discussions related to web designing and coding. We help our members to code their own website templates with HTML and CSS. We give them advice on various issues.

To know more about WebArtz Forum, visit the About Us page.

At the moment, you are viewing the forum as a guest. As a guest you can't make post and participate in discussions. You need to register and become a member of the forum. Click the register link below and become a part of this forum.

Thank You


You are not connected. Please login or register

View previous topic View next topic Go down  Message [Page 1 of 1]

1Regarding to the JQuery Slider Tut Empty 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
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>

2Regarding to the JQuery Slider Tut Empty Re: Regarding to the JQuery Slider Tut Mon Dec 27, 2010 11:49 am

ankillien

ankillien
Administrator
Administrator
Thats what jquery is known for. Write less, do more Razz

3Regarding to the JQuery Slider Tut Empty Re: Regarding to the JQuery Slider Tut Mon Dec 27, 2010 3:54 pm

Guest


Guest
ankillien wrote:Write less, do more Razz

yeah Razz

Sponsored content


View previous topic View next topic Back to top  Message [Page 1 of 1]

Permissions in this forum:
You cannot reply to topics in this forum