Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
problem with a premade text fade script
Old 07-07-2009, 01:44 PM problem with a premade text fade script
Junior Talker

Posts: 3
Name: Adam Ferestad
Trades: 0
hello everyone and i would like to thank you all for your help in advance. i will start off by saying that i am not much of a coder and am in need of some help customizing a premade script that fades in and out text to allow it to handle images as well. it works exactly as i need it to, other than the fact it won't load images. my client needs it to be able to load images as well due to the purpose i am using the script for. does anyone have any idea for a work around or modification to the js i could use to accomplish this?
here is what i have so far and it loads the text perfectly (for security reasons i removed the actual messages):
Code:
var fader = new Array();
fader[0] = new fadeObject('fade0','ffffff','000000',20,20)
fader[0].msg[1] = "message 1";
fader[0].msg[2] = "message 2"
fader[0].msg[3] = "message 3"
fader[0].msg[4] = "message 4"
fader[0].msg[5] = "message 5"
fader[0].msg[6] = "message 6"
fader[0].msg[7] = "message 7"

function fadeObject(id, c1, c2, s1, s2) {
  var self = this;
  this.id      = id;
  this.elem    = false;
  this.colour  = {
    stt: [parseInt(c1.substr(0, 2), 16), parseInt(c1.substr(2, 2), 16), parseInt(c1.substr(4, 2), 16)],
    end: [parseInt(c2.substr(0, 2), 16), parseInt(c2.substr(2, 2), 16), parseInt(c2.substr(4, 2), 16)],
    now: [parseInt(c1.substr(0, 2), 16), parseInt(c1.substr(2, 2), 16), parseInt(c1.substr(4, 2), 16)]
  };
  this.steps   = [s1, s2];
  this.dir     = false;
  this.active  = false;
  this.queue   = [];
  this.msg     = [];
  this.message = 0;
  function d2h(num) {
    num = Math.round(num);
    return ((num < 16) ? "0" : "") + num.toString(16);
  }
  this.fade = function(message, direction) {
    this.elem = this.elem || document.getElementById(this.id);
    this.queue.push([message, direction]);
    for (var x = 0; x < this.queue.length; x++) {
      for (var y = x + 1; y < this.queue.length; y++) {
        if (this.queue[x][0] == this.queue[y][0] && this.queue[x][1] != this.queue[y][1]) {
          this.queue.splice(x, 1);
          this.queue.splice(y - 1, 1);
        }
      }
    }
    if (!this.active) setTimeout(function() { self.fadeLoop(); }, 10);
  };
  this.fadeLoop = function() {
    if (!this.active && this.queue.length) {
      if (this.dir && this.message != this.queue[0][0]) this.queue.unshift([this.message, false]);
      var msg = this.queue.shift();
      if (this.msg[msg[0]]) {
        this.active = true;
        this.elem.innerHTML = this.msg[this.message = msg[0]];
        this.dir = msg[1];
      }
    }
    if (this.dir) {
      var c1 = this.colour.stt, c2 = this.colour.end, s = this.steps[0];
    } else var c1 = this.colour.end, c2 = this.colour.stt, s = this.steps[1];
    for (var x = 0, cnow = "", inc = 0; x < 3; x++) {
      this.colour.now[x] += inc = (c2[x] - c1[x]) / s;
      cnow += this.colour.now[x] = (inc < 0) ? Math.max(this.colour.now[x], c2[x]) : Math.min(this.colour.now[x], c2[x]);
    } this.elem.style.color = "#" + d2h(this.colour.now[0]) + d2h(this.colour.now[1]) + d2h(this.colour.now[2]);
    if (cnow == c2.join("")) {
      this.active = false;
      if (!this.queue.length) {
        if (!this.dir) {
          if (this.msg[0]) {
            this.queue.push([0, true]);
            setTimeout(function() { self.fadeLoop(); }, 10);
          } else this.elem.innerHTML = "&nbsp;";
        }
      } else setTimeout(function() { self.fadeLoop(); }, 10);
    } else setTimeout(function() { self.fadeLoop(); }, 10);
  };
  if (window.addEventListener) {
    window.addEventListener('load', function() { self.fade(0, true); }, false); 
  } else if (window.attachEvent)
    window.attachEvent('onload', function() { self.fade(0, true); });
}

the script was found here.
__________________
Adam Ferestad Freelance Artist Northeast Ohio
Adalast is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 07-07-2009, 03:56 PM Re: problem with a premade text fade script
Junior Talker

Posts: 3
Name: Adam Ferestad
Trades: 0
ok, i've been in contact with the creator of the script and he helped to shed some light on how this script works and why it has the limitation of text only and no images. how he said i would have to get this to work would be by having a general opacity shift. unfortunately i cannot find a general opacity script that will function with the "buttons" in another part of the site. this is a function that i need in the script, so is there any way to shift what is here from a color change to a general opacity? again, thank you in advance for your help.
__________________
Adam Ferestad Freelance Artist Northeast Ohio
Adalast is offline
Reply With Quote
View Public Profile
 
Old 07-08-2009, 11:13 AM Re: problem with a premade text fade script
Junior Talker

Posts: 3
Name: Adam Ferestad
Trades: 0
(edit: i was begging for help... but i decided to leave the begging for the 72 hour mark instead of the 24 hour mark... but if anyone knows a solution it would be very welcomed)
__________________
Adam Ferestad Freelance Artist Northeast Ohio

Last edited by Adalast; 07-08-2009 at 11:14 AM..
Adalast is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to problem with a premade text fade script
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.33380 seconds with 12 queries