Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Smooth Show/Hide Effects? Is there a way?

Posted on 2004-08-23
4
355 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Question about traversing a tree using jQuery 7 33
html Uncheck Checkbox 2 25
HTML Anchor Link Problem 3 35
On Load function does not trigger on iPhone 4 30
Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
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…

809 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