yorgos
yorgos

Reputation: 1818

javascript error in IE

I need help with an error message I am getting in IE6+. Note though that the code is working fine.

Message: Object expected
Line: 38
Char: 4
Code: 0
URI: http://localhost/dropbox/panorama/index.php?lang=gr

What is actually at line 38 is the following:

<script type="text/javascript"> 
    $(document).ready(function(){
        slideShow();
    });
</script> 

LINE 38 is the one where I am calling my "slideShow()" function
Note also that these function is stored in an external file.

These are the contents of the external file:

$(function slideShow() {
    //Set the opacity of all images to 0
    $('#gallery li').css({opacity: 0.0});

    //Get the first image and display it (set it to full opacity)
    $('#gallery li:first').css({opacity: 1.0});

    //Call the gallery imgGallery to run the slideshow, 5000: 5 seconds interval
    setInterval('imgGallery()',4000);   
});

$(function imgGallery() {
    //Get the first image
    var current = ($('#gallery li.show')?  $('#gallery li.show') : $('#gallery li:first'));

    //Get next image, if reached last image, start over from the first image
    var next = ((current.next().length) ? (current.next()) : $('#gallery li:first'));


    //Set the fade in effect for the next image
    next.css({opacity: 0.0})
        .addClass('show')
        .animate({opacity: 1.0}, 1000);

    //Hide current image
    current.animate({opacity: 0.0}, 1000)
        .removeClass('show');
});

Any recommendations?

Upvotes: 0

Views: 282

Answers (4)

epascarello
epascarello

Reputation: 207537

You wrapped the functions slideshow and imgGallery inside of a jQuery object.

$(function slideShow(){

}

$(function imgGallery() { 
  ...
});

That means that they will not be in global scope. Remove the $() since it is not required.

Upvotes: 1

Alistair Laing
Alistair Laing

Reputation: 973

A quote from Paul Irish: "setInterval is a JERK!!" from Paul Irish : 10 Things I Learned from the jQuery Source. http://vimeo.com/12529436

Fast forward to 07:40 and lasts about 5mins. Intead of using setInterval you can use setTimeout and call itself.

Upvotes: 0

Chris
Chris

Reputation: 58292

The way IE references line numbers isn't always 100% depending how/if the file is included. Regardless comment all the code out of the slide show function, and see if it still throws the error, if it does the line number is actually pointing to something else.

If it doesn't, bring each line back 1 at a time until the error occurs.

Sadly this is the best way I know of debugging in ie6

Upvotes: 0

Thor Jacobsen
Thor Jacobsen

Reputation: 8851

try and replace setInterval('imgGallery()',4000); with setInterval(imgGallery,4000);
If that does not work, this should:
setInterval(function(){imgGallery();},4000)

Upvotes: 1

Related Questions