1

我正在为一个网站创建一个照片库,并且是 javascript 的新手。该画廊在 chrome、firefox 和 safari 中运行良好,但似乎不想在 IE 中运行。

当在图库中单击图像时,它会在站点右侧的较大窗口中显示,如果单击以查看较大的预览,则会显示一个花式框窗口。Internet Explorer 打开页面,但它没有在右侧显示图像,当单击更大的预览时,它会转到图像 URL。

我使用的 javascript 是:

$(document).ready(function () {
    $('.gallery_data').css('display', 'block');
    $('.gallery_thumbnails').css('width', '500px');
    $('.gallery_preview').css('display', 'block');
    $('.gallery_caption').css('display', 'block');
    $('.gallery_thumbnails a').click(function (e) {
        e.preventDefault();
        var photo_caption = $(this).attr('title');
        var photo_fullsize = $(this).attr('href');
        var photo_preview = photo_fullsize.replace("_fullsize", "_preview");
        $('.gallery_caption').slideUp(500);
        $('.gallery_preview').fadeOut(500, function () {
            $('.gallery_preload_area').html('<img src="' + photo_preview + '" />');
            $('.gallery_preload_area img').imgpreload(function () {
                $('.gallery_preview').html('<a class="overlayLink" title="' + photo_caption + '" href="' + photo_fullsize + '" style="background-image:url(' + photo_preview + ');"></a>');
                $('.gallery_preview').fadeIn(500);
                $('.gallery_caption').html('<p><a class="overlayLink zoom" title="' + photo_caption + '" href="' + photo_fullsize + '">View larger</a></p><p>' + photo_caption + '</p>');
                $('.gallery_caption').slideDown(500);
                setFancyBoxLinks();
                updateThumbnails();
            });
        });
    });

    var first_photo_caption = $('.gallery_thumbnails a').first().attr('title');
    var first_photo_fullsize = $('.gallery_thumbnails a').first().attr('href');
    var first_photo_preview = first_photo_fullsize.replace("_fullsize", "_preview");
    $('.gallery_preview').html('<a class="overlayLink" title="' + first_photo_caption + '" href="' + first_photo_fullsize + '" style="background-image:url(' + first_photo_preview + ');"></a>');
    $('.gallery_caption').html('<p><a class="overlayLink zoom" title="' + first_photo_caption + '" href="' + first_photo_fullsize + '">View larger</a></p><p>' + first_photo_caption + '<a href="' + first_photo_fullsize + '" style="background-image:url(' + first_photo_preview + ');"></a></p>');
    updateThumbnails();
    setFancyBoxLinks();
});

function setFancyBoxLinks() {
    $("a.overlayLink").fancybox({
        'titlePosition': 'over',
        'overlayColor': '#000',
        'overlayOpacity': 0.8,
        'transitionIn': 'elastic',
        'transitionOut': 'elastic',
        'autoScale': true
    });
}

function updateThumbnails() {
    $('.gallery_thumbnails a').each(function (index) {
        if ($('.gallery_preview a').attr('href') == $(this).attr('href')) {
            $(this).addClass('selected');
            $(this).children().fadeTo(250, .4);
        } else {
            $(this).removeClass('selected');
            $(this).children().css('opacity', '1');
        }
    });
}

任何帮助深表感谢。

谢谢

4

1 回答 1

0

使用 F12 在 IE 中调试我的 javascript 文件,发现我需要升级我的 jquery 版本。

还必须修改第 29 行的 fancybox.1.3.4.js 文件:

isIE6 = $.browser.msie && $.browser.version < 7 && !window.XMLHttpRequest,

                             to

isIE6 = navigator.userAgent.match(/msie [6]/i) && !window.XMLHttpRequest,

现在可以在所有浏览器中完美运行。谢谢

于 2013-11-11T20:41:55.453 回答