<?xml version="1.0" encoding="ISO-8859-1"?>

<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/">
	<channel>
		<title>Dynamic Drive Forums - Blogs - magicyte</title>
		<link>http://www.dynamicdrive.com/forums/blog.php?31099-magicyte</link>
		<description>Dynamic Drive help forum</description>
		<language>en</language>
		<lastBuildDate>Sun, 26 May 2013 05:47:19 GMT</lastBuildDate>
		<generator>vBulletin</generator>
		<ttl>10</ttl>
		<image>
			<url>http://www.dynamicdrive.com/forums/images/misc/rss.jpg</url>
			<title>Dynamic Drive Forums - Blogs - magicyte</title>
			<link>http://www.dynamicdrive.com/forums/blog.php?31099-magicyte</link>
		</image>
		<item>
			<title>Jasoop Project</title>
			<link>http://www.dynamicdrive.com/forums/entry.php?9-Jasoop-Project</link>
			<pubDate>Wed, 04 Mar 2009 02:31:49 GMT</pubDate>
			<description><![CDATA[I'm currently working on a simple JavaScript effects library called Jasoop. 
 
*jasoop.js*: 
 
 
Code: 
--------- 
var Effect = (function() { 
    var durations = { 
        "very fast": 500,]]></description>
			<content:encoded><![CDATA[<blockquote class="blogcontent restore">I'm currently working on a simple JavaScript effects library called Jasoop.<br />
<br />
<b>jasoop.js</b>:<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<pre class="bbcode_code"style="height:372px;">var Effect = (function() {
    var durations = {
        &quot;very fast&quot;: 500,
        &quot;fast&quot;: 750,
        &quot;normal&quot;: 1000,
        &quot;slow&quot;: 1500,
        &quot;very slow&quot;: 2000
    },
    styles = [],
    counter = 0,
    fader = setTimeout(function() {
        return false;
    }, 10);
    function Effect(el) {
        this.element = document.getElementById(el);
        this.style = this.element.style;
        this.visible = true;
        this.opacity = 100;
        this.queue = false;
        this.autodelete = false;
        this.loop = false;
        this.pause = true;
    }
    Effect.prototype = {
        move: function(x, y) {
            this.style.position = &quot;absolute&quot;;
            this.style.left = x + &quot;px&quot;;
            this.style.top = y + &quot;px&quot;;
        },
        toggle: function() {
            if (this.style.display == &quot;none&quot;) {
                this.style.display = &quot;block&quot;;
                this.visible = true;
            } else {
                this.style.display = &quot;none&quot;;
                this.visible = false;
            }
        },
        css: function(options) {
            var ss = (options.replace(/ /g, &quot;&quot;)).split(&quot;;&quot;);
            var privates = {};
            for (var i = 0; i &lt; ss.length;++i) {
                var s = ss[i].split(&quot;:&quot;);
                while (1) {
                    if (s[0].indexOf(&quot;-&quot;) != -1) {
                        s[0] = s[0].replace(new RegExp(s[0].substr(s[0].indexOf(&quot;-&quot;), 2), &quot;g&quot;), (s[0].substr(s[0].indexOf(&quot;-&quot;), 2))[1].toUpperCase());
                    } else {
                        break;
                    }
                }
                this.style[s[0]] = s[1];
            }
        },
        fadeIn: function(inc, dur) {
            this.fadeTo(100, inc, dur);
        },
        fadeOut: function(inc, dur) {
            this.fadeTo(0, inc, dur);
        },
        fadeTo: function(pt, inc, dur) {
            if (inc &gt; 0) {
                if (this.opacity &gt; pt) {
                    clearTimeout(fader);
                    this.opacity -= inc;
                    fader = setTimeout((function(effect) {
                        return function() {
                            if ((effect.opacity - inc) &gt;= pt)
                                effect.fadeTo(pt, inc, dur);
                            else
                                effect.opacity = pt;
                        };
                    })(this), (typeof dur == &quot;string&quot;) ? Math.floor(durations[dur] / (100 / Math.abs(inc))) : Math.floor(dur / (100 / Math.abs(inc))));
                } else {
                    if (this.opacity &lt; pt) {
                        clearTimeout(fader);
                        this.opacity += inc;
                        fader = setTimeout((function(effect) {
                            return function() {
                                if ((effect.opacity + inc) &lt;= pt)
                                    effect.fadeTo(pt, inc, dur);
                                else
                                    effect.opacity = pt;
                            };
                        })(this), (typeof dur == &quot;string&quot;) ? Math.floor(durations[dur] / (100 / Math.abs(inc))) : Math.floor(dur / (100 / Math.abs(inc))));
                    }
                }
            }
            if (this.opacity &lt; 0)
                this.opacity = 0;
            if (this.opacity &gt; 100)
                this.opacity = 100;
            this.style.filter = &quot;alpha(opacity = &quot; + this.opacity + &quot;)&quot;;
            this.style.KHTMLOpacity = this.opacity / 100;
            this.style.MozOpacity = this.opacity / 100;
            this.style.opacity = this.opacity / 100;
        },
        compute: function(options) {
            var ss = (options.replace(/ /g, &quot;&quot;)).split(&quot;;&quot;);
            var privates = {};
            for (var i = 0; i &lt; ss.length;++i) {
                var s = ss[i].split(&quot;:&quot;);
                while (1) {
                    if (s[0].indexOf(&quot;-&quot;) != -1) {
                        s[0] = s[0].replace(new RegExp(s[0].substr(s[0].indexOf(&quot;-&quot;), 2), &quot;g&quot;), (s[0].substr(s[0].indexOf(&quot;-&quot;), 2))[1].toUpperCase());
                    } else {
                        break;
                    }
                }
                privates[s[0]] = [s[0], s[1]];
            }
            if (arguments[1] !== undefined)
                privates.callback = arguments[1];
            styles.push(privates);
        },
        start: function(dur) {
            if (!this.pause) {
                if (counter &lt; styles.length) {
                    for (var i in styles[counter]) {
                        this.style[styles[counter][i][0]] = styles[counter][i][1];
                    }
                    if (styles[counter].callback !== undefined)(styles[counter].callback).apply(this);
                    setTimeout((function(effect) {
                        return function() {
                            effect.start(dur);
                        };
                    })(this), (typeof styles[counter].delay == &quot;string&quot;) ? Math.floor(durations[dur] / styles.length) : Math.floor(dur / styles.length));
                    counter++;
                } else {
                    if (this.autodelete)
                        this.reset();
                    else
                        counter = 0;
                    if (!this.autodelete &amp;&amp; this.loop)
                        this.start(dur);
                }
            } else {
                this.pause = false;
            }
        },
        stop: function() {
            this.pause = true;
        },
        reset: function() {
            styles = [];
            counter = 0;
        },
        addEvent: function(ev, response) {
            if (this.element.addEventListener)
                this.element.addEventListener(ev, response, false);
            else if (this.element.attachEvent) {
                var res = function() {
                    response.apply(this.element);
                };
                this.element.attachEvent(&quot;on&quot; + ev, res);
            } else
                this.element[&quot;on&quot; + ev] = response;
        },
        addEvents: function(evs, response) {
            for (var i = 0; i &lt; evs.length;++i)
                this.addEvent(evs[i], response);
        },
        constructor: Effect
    };
    return Effect;
})();</pre>
</div><b>Definition:</b> (suggested method)<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<pre class="bbcode_code"style="height:84px;">var myElement;

onload = function() {
    myElement = new Effect(&quot;elementId&quot;);
};</pre>
</div>It is strictly imperative that <code style="background-color: #FFFFBB">new Effect(&quot;elementId&quot;)</code> is placed <b>WITHIN</b> the brackets of the <code style="background-color: #FFFFBB">onload</code> code block. Leave the variable <code style="background-color: #FFFFBB">myElement</code> <b>OUTSIDE</b> to keep it a global variable. Of course, this is not the only method of definition, but suggested because it is quick and simple. Please don't forget that <code style="background-color: #FFFFBB">onload</code> can only be used within the global namespace. If you place it in a local namespace, it will not be recognized; to fix this, include the parent object <code style="background-color: #FFFFBB">window</code> like this: <code style="background-color: #FFFFBB">window.onload</code><br />
<br />
Jasoop is always being improved. Please check <a href="http://beta.magicyte.freehostia.com/snippets.php?n=1" target="_blank">here</a> for the latest updates. If you have any questions, suggestions, ideas, or code modifications/additions to make Jasoop better, feel free to PM or e-mail me.</blockquote>

]]></content:encoded>
			<dc:creator>magicyte</dc:creator>
			<guid isPermaLink="true">http://www.dynamicdrive.com/forums/entry.php?9-Jasoop-Project</guid>
		</item>
	</channel>
</rss>
