Solved

Smooth Show/Hide Effects? Is there a way?

Posted on 2004-08-23
4
348 Views
Last Modified: 2012-05-05
Can anyone make the show/hide effect of this script smooth?

basically I want the content to have an animated crisp, smooth and fast drop down..

script will be available in next post..
0
Comment
Question by:andreni78
  • 2
  • 2
4 Comments
 

Author Comment

by:andreni78
ID: 11877855

<script>
var imgs=["http://www.opera.com/graphics/buttons/red_buy.gif","http://www.opera.com/graphics/buttons/red_dl.gif"]
function toggle(obj,nm)
{
     obj.src=obj.src==imgs[0]?imgs[1]:imgs[0];
     theDiv=document.getElementById(nm);
     theDiv.style.display=theDiv.style.display=="none"?"":"none";
}
</script>
Body:
<table border=0>
<tr>
     <td>
          <img src=http://www.opera.com/graphics/buttons/red_dl.gif onClick="toggle(this,'Arts')" border=0>
     </td>
</tr>
<tr>
     <td>
        <div id="Arts" style="position: relative; display:none;">
          Some content         Some content         Some content
         Some content          Some content         Some content         Some content
         Some content          Some content         Some content         Some content
         Some content          Some content         Some content         Some content
         Some content          Some content         Some content         Some content
         Some content          Some content         Some content         Some content
         Some content          Some content         Some content         Some content
         Some content          Some content         Some content         Some content
         Some content          Some content         Some content         Some content
         Some content
     </div>
     </td>
</tr>
</table>
0
 
LVL 10

Accepted Solution

by:
m8rix earned 500 total points
ID: 11878528
<html>

<head>
<title></title>
</head>

<body>
<script>

var imgs=["http://www.opera.com/graphics/buttons/red_buy.gif","http://www.opera.com/graphics/buttons/red_dl.gif"]
function toggle(obj,nm)
{
     obj.src=obj.src==imgs[0]?imgs[1]:imgs[0];
     theDiv=document.getElementById(nm);
     theDiv.style.top=getOffsetTop(obj)+23;
     theDiv.style.left=getOffsetLeft(obj);
     theDiv.style.pixelWidth=document.body.offsetWidth-50
     theDiv.style.display=theDiv.style.display=="none"?"":"none";
     animate(theDiv.id);
}
function animate(obj){
objID = document.getElementById(obj);
objID.style.color='#D1CCC5';
objID.style.pixelHeight=1
      if (objID.style.display ==""){
            changeheight(obj);
      }
}

function changeheight(obj,height){
objID = document.getElementById(obj);
if (height==undefined){height=1;}
objID.style.pixelHeight=height
//if (height==11){alert(objID.style.innerHeight);}
if (height<300){
  setTimeout("changeheight('" + obj + "'," + (height+5) + ")",5);}
else {objID.style.color='#000000';}
}

function getOffsetLeft (el) {
  var ol = el.offsetLeft;
  while ((el = el.offsetParent) != null)
    ol += el.offsetLeft;
  return ol;
}

function getOffsetTop (el) {
  var ot = el.offsetTop;
  while((el = el.offsetParent) != null)
   ot += el.offsetTop;
  return ot;
}
</script>
Body:
<table border=0>
<tr>
     <td>
          <img src=http://www.opera.com/graphics/buttons/red_dl.gif onClick="toggle(this,'Arts')" border=0 width="128" height="23">
     </td>
</tr>
<tr>
     <td>
        <div id="Arts" style="width:300;padding: 5px; position: absolute; display:none; background: #D1CCC5; overflow: hidden; height:1px;border: 1 solid #663300;color:#D1CCC5;">
          Some content         Some content         Some content
         Some content          Some content         Some content         Some content
         Some content          Some content         Some content         Some content
         Some content          Some content         Some content         Some content
         Some content          Some content         Some content         Some content
         Some content          Some content         Some content         Some content
         Some content          Some content         Some content         Some content
         Some content          Some content         Some content         Some content
         Some content          Some content         Some content         Some content
         Some content
     </div>
     </td>
</tr>
</table>
</body>

</html>
0
 

Author Comment

by:andreni78
ID: 11878828
very nice work!! but.. . it's not working right on my form.. it goes down smoothly but:

1. not fast enough
2. it makes my centered webpage turn to left indent
3. my form within the <div></div> is actually longer than what this script is set to go down... so it stops abruptly...

so if you could make this script relative to it's surroundings.. that would be fantastic.. and no grays please =)

looks like u spent a lot of time writing this script.. so i'll make another post requesting fixes...
0
 
LVL 10

Expert Comment

by:m8rix
ID: 12186729
Thanks for the feedback, as you may have probably noticed I have been away for a month. Is everything in order now or do you still require some assistance?
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now