javascript - jQuery - 自定义图库 - 适用于 FF、Chrome、Safari 和 IE8,但不适用于 IE7 - 指针?

标签 javascript jquery debugging internet-explorer-7

我对以下内容感到非常困惑。

当在 FF/Chrome 等中创建图库时,单击“下一步”会将图​​像移动到其中,并且保持悬停状态以供您再次单击。在 IE7 中,图像移动到一张上,然后悬停状态失败,并且不再出现。我在页面上设置的其他效果继续发挥作用。

我的 jQuery 可能不是最好的,所以我对造成的困惑表示歉意。除了手头的问题之外,欢迎任何一般的 jQuery 指针。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtm11-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" >
<head>
    <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
    <meta name="author" content="" />
    <meta name="keywords" content="" />
    <meta name="description" content="" />
    <meta name="robots" content="all" />

    <title>GA - 2009 yee haw</title>
    <script type="text/javascript"></script>
    <script type="text/javascript" src="/js/jquery-1.3.2.min.js"></script>
    <script type="text/javascript" src="/js/jquery.dimensions.min.js"></script>
    <script type="text/javascript" src="/js/jquery.easing.1.3.js"></script>
    <style type="text/css" media="all">
        @import "/css/screen.css";
    </style>
</head>


<body>





            <script type="text/javascript">
                <!--//
                function DrawGalleryOptions(div) {

                    $('gallery').css({width: '503px'});
                    $(div).append('<div class="gallery-title"><p style="font-size:14px;">no title</p><div class="gallery-bg gallery-bg-small"></div></div>');
                    $(div).append('<div class="gallery-nav"></div>');
                    $('.gallery-nav').append('<div class="gallery-bg"></div><div class="gallery-controls"><p class="gall-title"><a class="gallleft" href="#galleryleft" title="">Previous Image</a><a class="gallright" href="#galleryright" title="">Next Image</a></p></div>');

                    $('.gallery-title, .gallery-nav, .gallery-bg').css({ position: 'absolute', left: '0px', height: '30px', width: '503px' });
                    $('.gallery-nav').css({ height: '60px', bottom: '-60px' });
                    $('.gallery-bg').css({ backgroundColor: '#5974c5', opacity: 0.7, height: '60px', zIndex: 1000 });
                    $('.gallery-title').css({ top: '-30px'});
                    $('.gallery-controls').css({ position: 'absolute', zIndex: 1002 });
                    $('.gallery-bg-small').css({height: '30px'});
                    $('.gallery-title p').css({zIndex: 1002, color: '#ffffff', position: 'absolute', padding: '5px'});
                    $('.gallery-controls p').css({ posistion: 'absolute', zIndex: 1005, left: '0px', top: '0px' });
                    $('a.gallleft').css({ width: '82px', height: '45px', display: 'block', textIndent: '0', backgroundImage: 'url(/image/galleryleft.gif)', backgroundPosition: 'left top', backgroundRepeat: 'no-repeat', fontSize: '11px', color: '#ffffff', top: '15px', left: '15px', position: 'absolute', paddingTop: '25px' });
                    $('a.gallright').css({ width: '53px', height: '45px', display: 'block', textIndent: '0', backgroundImage: 'url(/image/galleryright.gif)', backgroundPosition: 'right top', backgroundRepeat: 'no-repeat', fontSize: '11px', color: '#ffffff', top: '15px', left: '430px', position: 'absolute', paddingTop: '25px' });
                }

                function ShowGalleryOptions() {

                    jQuery.easing.def = "easeOutQuint";
                    $('.gallery-title').animate({ top: '0px' }, 800);
                    $('.gallery-nav').animate({ bottom: '0px' }, 800);

                }

                function HideGalleryOptions() {

                    $('.gallery-title').animate({ top: '-30px' }, 800);
                    $('.gallery-nav').animate({ bottom: '-60px' }, 800);

                }

                function StopAll() {

                    $('.gallery-title').stop();
                    $('.gallery-nav').stop();

                }


                function MoveGallery(pic) {

                    $('#test2').html('>> <br />' + pic[_GalleryCurrent].src + " " + pic[_GalleryCurrent].height + " " + pic[_GalleryCurrent].width + "<br />Current: " + _GalleryCurrent);

                    $('.gallery').append('<img id="gallery-current" style="display:none;" src="' + pic[_GalleryCurrent].src + '" width="' + pic[_GalleryCurrent].width + '" height="' + pic[_GalleryCurrent].height + '" alt="' + pic[_GalleryCurrent].alt + '" />');
                    $('#gallery-current').css({ opacity: 0, display: 'block' });
                    $('.gallery img').css({ position: 'absolute', top: '0px', left: '0px' });
                    //jQuery.easing.def = "easeOutElastic";

                    $('.gallery-title p').html(pic[_GalleryCurrent].alt);

                    $('#gallery-current').animate({ opacity: 1 }, 1200, function() {

                        $('#gallery-last').remove();
                        $('#gallery-current').attr('id', 'gallery-last');

                    });

                }


                $(function() {

                    var pic;
                    pic = $(".gallery").children("img");
                    _GalleryMax = pic.length - 1;
                    _GalleryCurrent = 0;

                    //$('#test2').html('>><br />' + pic[_].src + " " + pic[0].height + " " + pic[0].width + "<br />Current: " + _GalleryCurrent);

                    $('.gallery').css({ height: 283, overflow: 'hidden', position: 'relative' });
                    $('.gallery').html('');

                    DrawGalleryOptions('.gallery');

                    $('.gallery').append('<img id="gallery-last" src="' + pic[_GalleryCurrent].src + '" width="' + pic[_GalleryCurrent].width + '" height="' + pic[_GalleryCurrent].height + '" alt="' + pic[_GalleryCurrent].alt + '" />');
                    $('.gallery-title p').html(pic[_GalleryCurrent].alt);

                    $('.gallery').hover(function() {

                        //alert('on');
                        StopAll();
                        ShowGalleryOptions();

                    },
                    function() {

                        //alert('off');
                        StopAll();
                        HideGalleryOptions();

                    });

                    $('a.gallright').click(function() {

                        $('#gallery-current').stop(false, true);

                        //alert('boota');
                        _GalleryCurrent = _GalleryCurrent + 1;
                        if (_GalleryCurrent > _GalleryMax) {
                            _GalleryCurrent = 0;
                        }

                        MoveGallery(pic);

                    });

                    $('a.gallleft').click(function() {

                        $('#gallery-current').stop(false, true);

                        //alert('boota');
                        _GalleryCurrent = _GalleryCurrent - 1;
                        if (_GalleryCurrent < 0) {
                            _GalleryCurrent = _GalleryMax;
                        }

                        MoveGallery(pic);

                    });

                });

                //-->

            </script>

            <div class="gallery">

                <img class="gall-img" src="/image/gallery1.jpg" width="503" height="283" alt="Person on a lake" />
                <img class="gall-img" src="/image/gallery2.jpg" width="503" height="283" alt="Building university" />
                <img class="gall-img" src="/image/gallery3.jpg" width="503" height="283" alt="Random colours" />
                <img class="gall-img" src="/image/gallery4.jpg" width="503" height="283" alt="Abstract - dark blue?" />
                <img class="gall-img" src="/image/gallery5.jpg" width="503" height="283" alt="Random abstract" />

            </div>

            <div id="test2" style="font-size:18px;"></div>


</body>
</html>

非常感谢任何帮助!!

编辑#1: 除上述内容外,我读到 IE7 的 img 选择器存在问题,但我尝试将其更改为通用类名等,但无济于事。还有更多线索吗?

编辑#2: 我仍然在努力解决这个问题 - 我在这里添加了一个实例:(看起来太新了,无法添加链接,抱歉!)

最佳答案

修复了玩了很多次后的问题。正如 Keith 所说,这只是一个 CSS 错误。

IE7 需要提醒一些元素所处的 zindex 级别,因此我插入了以下内容

$('.gallery-nav, .gallery-title').css({ position: 'absolute', left: '0px', zIndex: '1100' }); // random reassignement of gallery zIndex, because IE7 doesn't behave

在移动图库功能内(就在动画之前)。

快乐!

关于javascript - jQuery - 自定义图库 - 适用于 FF、Chrome、Safari 和 IE8,但不适用于 IE7 - 指针?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/892929/

相关文章:

javascript - jQuery 倒数计时器未显示在浏览器中

javascript - ajax请求后页面刷新

javascript - Javascript split.length 仅返回 1 但为什么呢?

javascript - 当添加新行时,输入名称会增加 1?

javascript - 如何在jvectormap中添加路径作为参数?

javascript - 在循环中添加div jquery

c - 解释 C 中这个 "static variable"的行为

javascript - 将鼠标悬停在 div 上时,多个图像取决于鼠标位置

c# - 我可以阻止 CLR 优化掉调试信息吗?

c++ - fstream 产生非常奇怪的行为