Read the News & Services Alerts Before Creating A Support Thread







x10Hosting Community » Site Design & Development » Programming Help » Project please help

Reply
Old 05-27-2009, 09:45 PM   #1 (permalink)
Community Advocate
 
Twinkie's Avatar
 
Join Date: Sep 2007
Location: Ft. Lauderdale, Florida
Posts: 1,293
Credits: 11,793
iTrader: (0)
Twinkie is an unknown quantity at this point

Last Achievements
Send a message via MSN to Twinkie
Project please help

I have a school project due tomorrow, that for the life of me I cannot get to work. I made a web collage, with an image fade in function that fades the images in when they load. It gives me a generic error, $("chalkboard") is null when the ID is clearly declared. This generic sort of error can be set off by an error anywhere else on the page, and I cannot find it. Please help me out!
__________________
~~Twinkie~~



Last edited by Twinkie; 05-27-2009 at 09:46 PM..
Twinkie is offline   Reply With Quote
Old 05-27-2009, 10:26 PM   #2 (permalink)
x10 Lieutenant
 
gomarc's Avatar
 
Join Date: Oct 2007
Location: USA
Posts: 363
Credits: 7,081
iTrader: (3)
gomarc is an unknown quantity at this point

Last Achievements
Re: Project please help

In main.css

lines 25 and 31

replace
Code:
table.body td#chalkboard
With
Code:
table.body td.chalkboard
__________________

Last edited by gomarc; 05-27-2009 at 10:27 PM..
gomarc is offline   Reply With Quote
Old 05-27-2009, 10:33 PM   #3 (permalink)
Community Advocate
 
Twinkie's Avatar
 
Join Date: Sep 2007
Location: Ft. Lauderdale, Florida
Posts: 1,293
Credits: 11,793
iTrader: (0)
Twinkie is an unknown quantity at this point

Last Achievements
Send a message via MSN to Twinkie
Re: Project please help

Thanks gomarc, but that is referring to the correct element, the <td> with the ID of chalkboard. I tried separating the id and the classes to see if that works, but that didn't help either.
__________________
~~Twinkie~~


Twinkie is offline   Reply With Quote
Old 05-28-2009, 05:22 AM   #4 (permalink)
Community Advocate
 
Join Date: Mar 2008
Location: Libertatia
Posts: 1,061
Credits: 10,357
iTrader: (0)
misson is an unknown quantity at this point

Last Achievements
Re: Project please help

Quote:
Originally Posted by Twinkie View Post
It gives me a generic error, $("chalkboard") is null when the ID is clearly declared.
That particular line is executed before the body even loads. <td id="chalkboard"> doesn't exist yet. Either load the script at the end of the body or hook the load event for window.

If you don't have it instaled, get Firebug. I bet you would have figured this out on your own with it.

And you really shouldn't be using tables for layout.
misson is offline   Reply With Quote
Old 05-28-2009, 04:27 PM   #5 (permalink)
Community Advocate
 
Twinkie's Avatar
 
Join Date: Sep 2007
Location: Ft. Lauderdale, Florida
Posts: 1,293
Credits: 11,793
iTrader: (0)
Twinkie is an unknown quantity at this point

Last Achievements
Send a message via MSN to Twinkie
Re: Project please help

Thanks for the catch mission

It still is not working even after I moved the javascript down below the table? Now it shows no error but it still does not fade in?
__________________
~~Twinkie~~



Last edited by Twinkie; 05-28-2009 at 04:28 PM..
Twinkie is offline   Reply With Quote
Old 05-28-2009, 05:09 PM   #6 (permalink)
Community Advocate
 
Join Date: Mar 2008
Location: Libertatia
Posts: 1,061
Credits: 10,357
iTrader: (0)
misson is an unknown quantity at this point

Last Achievements
Re: Project please help

Did you try Firebug?
misson is offline   Reply With Quote
Old 05-28-2009, 05:35 PM   #7 (permalink)
Community Advocate
 
Twinkie's Avatar
 
Join Date: Sep 2007
Location: Ft. Lauderdale, Florida
Posts: 1,293
Credits: 11,793
iTrader: (0)
Twinkie is an unknown quantity at this point

Last Achievements
Send a message via MSN to Twinkie
Re: Project please help

Yes I did, and to be honest I don't know how to use it. I didn't see to red lights in any of the tabs, so I don't think it caught anything.

I will figure it out a bit later when I have the time, but as I said it is a project do tomorrow, so please help me if you can.

I know I said that yesterday, but I am pretty sure tomorrow is when I will have to present, so any help would be appreciated.
__________________
~~Twinkie~~



Last edited by Twinkie; 05-28-2009 at 05:38 PM..
Twinkie is offline   Reply With Quote
Old 05-28-2009, 07:18 PM   #8 (permalink)
Community Advocate
 
Join Date: Mar 2008
Location: Libertatia
Posts: 1,061
Credits: 10,357
iTrader: (0)
misson is an unknown quantity at this point

Last Achievements
Re: Project please help

If you don't understand how to do any of the following Firebug tasks, read a Firebug debugging (Michael Sync's tutorial looks good).

Switch to 'fadein.js' and set a breakpoint (that red dot) on the 'for' loop that adds the load event listener. First thing you'll notice is you can't inspect $('chalkboard') as an object and document.getElementById() is called repeatedly. This is a hint you should store $('chalkboard') in a local variable. Use a function so you don't pollute the global namespace.
Code:
(function () {
  var chalkboard = $('chalkboard');
  for (var i = 0; chalkboard.childNodes.length > i; i++) {
    ...
  }
})();
The second thing you'll notice is the "if (!$("chalkboard").childNodes[i].src)" test always succeeds. When you inspect the chalkboard variable (after you add it to the code) you'll find that none of its children are <img>s, they're all <div>s. If you loop over chalkboard's grandchildren, you'll find the images. Better is to loop over chalkboard.getElementsByTagName('img') rather than chalkboard.childNodes.

An alternative is to add a class to the images you want to fade in and loop over document.images.

Lastly, consider using addEventListener/attachEvent rather than the onload attribute. You can create wrappers around the browser native event registration methods to work with a consistent interface.
Code:
var addEventListenerTo, removeEventListenerFrom;
if (window.attachEvent) {
    addEventListenerTo = function(element, eventName, listener) {
        /* Proper implementation is non-trivial:
           + 'listener' should get the fired event as 1st argument.  
           + 'eventName' is the DOM event name, which doesn't start with 'on'.  'attachEvent' expects event names
               to begin with 'on'.  Not all DOM events can be mapped to an IE event by prefixing 'on'.  
           + IE will leak event listeners.  When you add a listener, hook window's unload event to detach the listener.
           + Within the listener, 'this' must be bound to the object the listener is registered on, which is 
           + 'element'.
           + The biggest issue (because it's not solvable using IE events) is that event capturing can't be supported.
               Oh, well.
           The more you implement, the more useful the library is.  Not all of the features need to be 
           implemented immediately; they can be added as needed.  Ain't separation of concerns grand?
        */
    }
    removeEventListenerFrom = function(element, event, listener) {
        // implementation is almost trivial.
    }
} else {
    addEventListenerTo = function(element, event, listener) {
        // implementation is trivial
    }
    removeEventListenerFrom = function(element, event, listener) {
        // implementation is trivial
    }
}
As this assignment has a close deadline, consider writing addEventListenerTo for the next assignment.
misson is offline   Reply With Quote
Old 05-28-2009, 10:01 PM   #9 (permalink)
Community Advocate
 
Twinkie's Avatar
 
Join Date: Sep 2007
Location: Ft. Lauderdale, Florida
Posts: 1,293
Credits: 11,793
iTrader: (0)
Twinkie is an unknown quantity at this point

Last Achievements
Send a message via MSN to Twinkie
Re: Project please help

Thanks for the tip about the addeventlistner, but that over complicates the script. I have scriptors block right now, so I need the script to be very simple.

Code:
var chalkboard = $('chalkboard').getElementsByTagName('img');
for (i in chalkboard) {
	if (!chalkboard[i].src) continue;
	chalkboard[i].onload=function() {
		var obj = chalkboard[i];
		setOpacity(obj, 0);
  		obj.style.visibility = 'visible';
  		fadeIn(obj,0);
	}
}
Why is variable i not able to be read by the onload function declaration?
__________________
~~Twinkie~~


Twinkie is offline   Reply With Quote
Old 05-28-2009, 11:04 PM   #10 (permalink)
x10 Lieutenant
 
gomarc's Avatar
 
Join Date: Oct 2007
Location: USA
Posts: 363
Credits: 7,081
iTrader: (3)
gomarc is an unknown quantity at this point

Last Achievements
Re: Project please help

Maybe this article can help you:

http://brainerror.net/scripts/javascript/blendtrans/
__________________
gomarc is offline   Reply With Quote
Reply

Thread Tools
Display Modes

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 On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
is this project will be good for my academic? balaji2u Off Topic 0 12-12-2008 11:03 AM
A Project For My Academic balaji2u Off Topic 4 11-03-2008 01:06 AM
Project Wonderful JuniorD Earning Money 2 09-16-2008 02:35 AM
New web project. ingjpd00 Graphics & Webdesign 4 10-04-2005 07:55 AM
Project XeoX - Anyone want to help? Nekaid Scripts & 3rd Party Apps 6 07-22-2005 09:05 PM


All times are GMT -5. The time now is 11:53 AM.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios



Content Relevant URLs by vBSEO 3.3.0