+ Reply to Thread
Page 1 of 2
1 2 LastLast
Results 1 to 10 of 16

Thread: Project please help

  1. #1
    Community Advocate Twinkie is an unknown quantity at this point Twinkie's Avatar
    Join Date
    Sep 2007
    Location
    Ft. Lauderdale, Florida
    Posts
    1,337

    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!
    Last edited by Twinkie; 05-27-2009 at 08:46 PM.
    ~~Twinkie~~



  2. #2
    x10 Lieutenant gomarc is an unknown quantity at this point gomarc's Avatar
    Join Date
    Oct 2007
    Location
    USA
    Posts
    379

    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 09:27 PM.

  3. #3
    Community Advocate Twinkie is an unknown quantity at this point Twinkie's Avatar
    Join Date
    Sep 2007
    Location
    Ft. Lauderdale, Florida
    Posts
    1,337

    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~~



  4. #4
    Community Advocate misson is an unknown quantity at this point
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    1,130

    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.

  5. #5
    Community Advocate Twinkie is an unknown quantity at this point Twinkie's Avatar
    Join Date
    Sep 2007
    Location
    Ft. Lauderdale, Florida
    Posts
    1,337

    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?
    Last edited by Twinkie; 05-28-2009 at 03:28 PM.
    ~~Twinkie~~



  6. #6
    Community Advocate misson is an unknown quantity at this point
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    1,130

    Re: Project please help

    Did you try Firebug?

  7. #7
    Community Advocate Twinkie is an unknown quantity at this point Twinkie's Avatar
    Join Date
    Sep 2007
    Location
    Ft. Lauderdale, Florida
    Posts
    1,337

    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.
    Last edited by Twinkie; 05-28-2009 at 04:38 PM.
    ~~Twinkie~~



  8. #8
    Community Advocate misson is an unknown quantity at this point
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    1,130

    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.

  9. #9
    Community Advocate Twinkie is an unknown quantity at this point Twinkie's Avatar
    Join Date
    Sep 2007
    Location
    Ft. Lauderdale, Florida
    Posts
    1,337

    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~~



  10. #10
    x10 Lieutenant gomarc is an unknown quantity at this point gomarc's Avatar
    Join Date
    Oct 2007
    Location
    USA
    Posts
    379

    Re: Project please help

    Maybe this article can help you:

    http://brainerror.net/scripts/javascript/blendtrans/

+ Reply to Thread
Page 1 of 2
1 2 LastLast

Similar Threads

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts