views:

369

answers:

1

I've implemented a slideshow using the Cycle plugin, which is working in all browsers except IE6&7, where the images just show up in a list, and the #page_copy div is not hiding. I've been going through the code all day without any luck, and not exactly sure how or what I should be looking for.

What would be the best way to go about debugging this issue? I know that the #page_copy div is hiding when I remove the rest of the code, and I've tried the reverse (which had no result)

<script type="text/javascript" charset="utf-8">
        jQuery.fn.fadeToggle = function(speed, easing, callback) { 
            return this.animate({opacity: 'toggle'}, speed, easing, callback); 
        };


        $(document).ready(function() {
            $('#page_copy').hide();
            $('a#info_close_button').click(function() {
                $('#page_copy').fadeOut(200);
                return false;
            });
            $('a#info_button').click(function() {
                $('#page_copy').fadeToggle(200);
                return false;
            });
        });


        $(window).load(function() {
            // vertically center single image
            var $image_cnt = $("#images > img").size();
            if($image_cnt < 2) {
                var $single_img = $("#images").children(':first-child');
                var h = $single_img.height();
                $single_img.css({
                    marginTop: (620 - h) / 2,
                });
                $(".next").css("display","none");
                $(".prev").css("display","none");
            }
        });


        // wait until images have loaded before starting cycle
        $(window).load(function() {
            // front image rotator
            $('#images').cycle({ 
                fx: 'fade',
                speed:  300, 
                next:   '.next', 
                prev:   '.prev',
                containerResize: 0,
                timeout:  0, 
                delay:   -2000,
                before: onBefore
            });

        }); 

        // hide all but the first image when page loads
        $(document).ready(function() {
            $('#images img:gt(0)').hide();
        });

        // callback fired when each slide transition begins
        function onBefore(curr,next,opts) {
            var $slide = $(next);
            var w = $slide.width();
            var h = $slide.height();
            $slide.css({
                marginTop: (620 - h) / 2,
                marginLeft: (650 - w) / 2
            });
        };
    </script>
+1  A: 

I don't really get why you have multiple $(document).ready and $(window).load..

Maybe you should just try and place everything in a single $(document).ready block.

Additionally move the definition of function onBefore(...) at the very start of the <script> tag. Directly before the jQuery.fn.fadeToggle code.

Try also removing the unneeded comma at the end of this piece of code

$single_img.css({
    marginTop: (620 - h) / 2, //<---- remove comma
});

And also remove this unneeded semi-colon

function onBefore(curr,next,opts) {...}; //<--- unneeded
jitter
thanks for the tips jitter. I removed that comma and semi-colon, and moved all the code in to one $(document).ready and one $(window).load, but still have the same issues. There needs to be both otherwise the image size isn't evaluated in time if everything is in a doc.ready
Aaron Moodie
yes, it was the comma!! Thanks Jitter.
Aaron Moodie