[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Dynamically fading table

Posted on 2006-07-05
9
Medium Priority
?
1,232 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

649 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