?
Solved

Dynamically fading table

Posted on 2006-07-05
9
Medium Priority
?
1,230 Views
Last Modified: 2012-06-27
Hello, I use the following to fade the content of a table:
http://www.experts-exchange.com/Web/Web_Languages/JavaScript/Q_21909311.html

It works well, but it is jumpy.  I want it to be a smooth transition, so that in 1 second, it fades from 100% opacity to 50% opacity.  This needs to be cross browser.

Any ideas?

Thanks!



<style>
.yourClass {
     filter:alpha(opacity=50);
     opacity: 0.50;
     -moz-opacity:0.50;
     }
</style>
<script>
///// thanks pravinasar and 0h4crying0utloud

function fadeTable(tname) {
  document.getElementById(tname).className = "yourClass";
}
</script>

<a href=#" onclick="return fadeTable('myTable');return false">fade table</a>

<table id="myTable" width=550 class="mytableclass" background="http://www.google.com/images/logo.gif"><tr><td height=210>cell 1</td><td>cell 2</td><td>cell 3</td></tr></table>
0
Comment
Question by:hankknight
[X]
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
  • 5
  • 4
9 Comments
 
LVL 18

Expert Comment

by:bruno
ID: 17046946
I know they provided you with the fade script, but you might want to look at the Yahoo UI LIbrary animation script, here is their "fade" example":
http://developer.yahoo.com/yui/examples/animation/fade.html

Get more info about the animation utility here:
http://developer.yahoo.com/yui/animation/


bruno  
0
 
LVL 16

Author Comment

by:hankknight
ID: 17046971
Thanks.  That is very interesting, but a bit heavier than I would like.  I would like to see this accomplished with a fraction the amount of code that Yahoo's animation uses.
0
 
LVL 18

Expert Comment

by:bruno
ID: 17047343
ok - but i assume that's more the effect you want?  let me work up some code for you
0
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
LVL 16

Author Comment

by:hankknight
ID: 17047420
Thanks, yes, that is what I am looking for, but I want it as lightweight as possible.
0
 
LVL 18

Expert Comment

by:bruno
ID: 17047422
here's what i have currently, for firefox only - i need to find the js to change the filter value for IE, but this should get you started:



<script>
fade = {
    speed : 5,
    finalOpacity : 30,
    currentOpacity : 100,
    elID : null,
    init : function(el) {
        fade.elID = el;
        if (!document.getElementById(el)) return;
            fadeInterval = setInterval('fade.doFade()',fade.speed);
    },
    doFade : function(obj) {
        obj = document.getElementById(fade.elID);
        if (fade.currentOpacity>fade.finalOpacity) {
            var newOpacity = fade.currentOpacity - 1;
            obj.style.opacity = "."+(newOpacity);
            fade.currentOpacity = newOpacity;
        } else {
            clearInterval(fadeInterval);
        }
    }
}
</script>

<a href=#" onclick="fade.init('myTable');return false">fade table</a>

<table id="myTable" width=550 class="mytableclass" background="http://www.google.com/images/logo.gif"><tr><td height=210>cell 1</td><td>cell 2</td><td>cell 3</td></tr></table>
0
 
LVL 18

Accepted Solution

by:
bruno earned 2000 total points
ID: 17047430
easier than i thought it would be to add the IE functionality - here is the entire thing:


<script>
fade = {
    speed : 5,
    finalOpacity : 30,
    currentOpacity : 100,
    elID : null,
    init : function(el) {
        fade.elID = el;
        if (!document.getElementById(el)) return;
            fadeInterval = setInterval('fade.doFade()',fade.speed);
    },
    doFade : function(obj) {
        obj = document.getElementById(fade.elID);
        if (fade.currentOpacity>fade.finalOpacity) {
            var newOpacity = fade.currentOpacity - 1;
            obj.style.opacity = "."+(newOpacity);
            obj.style.filter = "alpha(opacity="+newOpacity+")";
            fade.currentOpacity = newOpacity;
        } else {
            clearInterval(fadeInterval);
        }
    }
}
</script>

<a href=#" onclick="fade.init('myTable');return false">fade table</a>

<table id="myTable" width=550 class="mytableclass" background="http://www.google.com/images/logo.gif"><tr><td height=210>cell 1</td><td>cell 2</td><td>cell 3</td></tr></table>
0
 
LVL 18

Expert Comment

by:bruno
ID: 17047438
btw - i normally like to keep styles seperate from the JS, as was in your original script.  i'd rather change the class name than update the styles dynamically.  but in this situation that doesn't work as you'd need at least 50 different classes, one for each opacity level, and that simply isn't worth it.  

so, we've set all your variables at the top of the script so they are easy to locate and change, and none of the actual values are buried anywhere within the script.
0
 
LVL 16

Author Comment

by:hankknight
ID: 17048144
Thanks!  It is perfect.
0
 
LVL 16

Author Comment

by:hankknight
ID: 17048489
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

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…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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…
Suggested Courses

770 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