Jquery slidershow 跨浏览器实现失败

发布于 2024-11-13 10:40:05 字数 4395 浏览 1 评论 0原文

这是我的图像滑块轮播的代码,该轮播设置为页面的 100% 宽度。我的问题是为什么这在除 IE 版本之外的所有版本上都能正常工作? IE 8=轮播已结束。 IE 7/6 = 所有图像都堆叠起来。

看看它: http://henryquindara.com/_this/

JS:

var imageContainer = $('#imageContainer .container');
var imgs = $('#imageContainer .container .imageThumb');
var imgsDisp = $('#imageContainer .container .imageThumb img');
var imgsWidth;
var navWidth = 0;
var windowWidth = $(window).width();
var cnt = 0;
var imgOffset;
var navOffset;
var curImg = 1;

$(window).resize(function() 
{
    windowWidth = $(window).width();
    imgOffset =  (imgsWidth - windowWidth) / windowWidth;
    navOffset = (navWidth - windowWidth) / windowWidth;
    $('#imageContainer').css('width',windowWidth);
});

imageContainer.find('img').each(function()
{
    var $img    = $(this);
    $img.load(function()
    {
        ++cnt;
        if(cnt == imgs.length)
        {
            imgWidth = imageContainer.find('.imageThumb:first').width();
            imgHeight = imageContainer.find('.imageThumb:first').height();
            imgsWidth = (imgWidth * imgs.length) + (5 * imgs.length);
            imgOffset =  (imgsWidth - windowWidth) / windowWidth;
            $('#imageContainer').css({width:windowWidth});
            $('#imageContainer .container').css({width:imgsWidth});
            centerCurImg();
        }
        sizeImg($img, imageContainer.find('.imageThumb:first').width()-0, imageContainer.find('.imageThumb:first').height()-0);
        $img.css({'opacity':'.4'});
    })
});

$('#prev-btn').click(prevClickAdj);
$('#next-btn').click(nextClickAdj);

function centerCurImg()
{
    var destX = (windowWidth / 2 ) - (imgWidth*(curImg+1)) + (imgWidth/2);
    imageContainer.stop().animate({left:destX}, 400, 'easeOutCirc', function(){
        sizeHot();
    });
}

function sizeHot()
{
    $(imgsDisp[curImg]).stop().animate({height:imgHeight, width:imgWidth, opacity:1}, 400, 'easeOutCirc');

}

function sizeImg ( target, val, val2 )
{
    $(target).css({'width' : val, 'height' : val2});
}

function prevClickAdj()
{
    $(imgsDisp[curImg]).stop().animate({height:imgHeight-0, width:imgWidth-0, opacity:.4}, 400, 'easeOutCirc', function()
            {
        centerCurImg(); 
    });

    curImg --;
    checkArrows();

}

function nextClickAdj()
{
    //$(imgsDisp[curImg]).stop().animate({height:imgHeight-0, width:imgWidth-0, opacity:.4}, 400, 'easeOutCirc', function()
            {
        centerCurImg(); 
    });

    curImg ++;
    checkArrows();  
}

function checkArrows()
{
    if ( curImg > 0 )  $('#prev-btn').show();
    else $('#prev-btn').hide(); 

    if ( curImg < imgs.length-1 )  $('#next-btn').show();
    else $('#next-btn').hide(); 
}

HTML< /强>

            <div id="imageContainer">

                <div class="container">

                    <div class="imageThumb"> 

                        <div class="imageFull"><img src="/images/newyork/img_1.jpg" /></div>

                    </div>

                    <div class="imageThumb"> 

                        <div class="imageFull"><img src="/images/newyork/img_2.jpg" /></div>

                    </div>

                    <div class="imageThumb"> 

                        <div class="imageFull"><img src="/images/newyork/img_3.jpg" /></div>

                    </div>

                    <div class="imageThumb"> 

                        <div class="imageFull"><img src="/images/newyork/img_1.jpg" /></div>

                    </div>

                    <div class="imageThumb"> 

                        <div class="imageFull"><img src="/images/newyork/img_2.jpg" /></div>

                    </div>

                    <div class="imageThumb"> 

                        <div class="imageFull"><img src="/images/newyork/img_3.jpg" /></div>

                    </div>

                </div>

            </div>



        <div id="prev-btn"><a href="#">Previous</a></div>

        <div id="next-btn"><a href="#">Next</a></div>

    </div>

任何帮助将不胜感激!

Here's my code for an image slider carousel that's set to 100% width of a page. My question is why does this work correctly on everything but versions of IE?
IE 8=Carousel is at the end.
IE 7/6 = All the images are stacked.

See it:
http://henryquindara.com/_this/

JS:

var imageContainer = $('#imageContainer .container');
var imgs = $('#imageContainer .container .imageThumb');
var imgsDisp = $('#imageContainer .container .imageThumb img');
var imgsWidth;
var navWidth = 0;
var windowWidth = $(window).width();
var cnt = 0;
var imgOffset;
var navOffset;
var curImg = 1;

$(window).resize(function() 
{
    windowWidth = $(window).width();
    imgOffset =  (imgsWidth - windowWidth) / windowWidth;
    navOffset = (navWidth - windowWidth) / windowWidth;
    $('#imageContainer').css('width',windowWidth);
});

imageContainer.find('img').each(function()
{
    var $img    = $(this);
    $img.load(function()
    {
        ++cnt;
        if(cnt == imgs.length)
        {
            imgWidth = imageContainer.find('.imageThumb:first').width();
            imgHeight = imageContainer.find('.imageThumb:first').height();
            imgsWidth = (imgWidth * imgs.length) + (5 * imgs.length);
            imgOffset =  (imgsWidth - windowWidth) / windowWidth;
            $('#imageContainer').css({width:windowWidth});
            $('#imageContainer .container').css({width:imgsWidth});
            centerCurImg();
        }
        sizeImg($img, imageContainer.find('.imageThumb:first').width()-0, imageContainer.find('.imageThumb:first').height()-0);
        $img.css({'opacity':'.4'});
    })
});

$('#prev-btn').click(prevClickAdj);
$('#next-btn').click(nextClickAdj);

function centerCurImg()
{
    var destX = (windowWidth / 2 ) - (imgWidth*(curImg+1)) + (imgWidth/2);
    imageContainer.stop().animate({left:destX}, 400, 'easeOutCirc', function(){
        sizeHot();
    });
}

function sizeHot()
{
    $(imgsDisp[curImg]).stop().animate({height:imgHeight, width:imgWidth, opacity:1}, 400, 'easeOutCirc');

}

function sizeImg ( target, val, val2 )
{
    $(target).css({'width' : val, 'height' : val2});
}

function prevClickAdj()
{
    $(imgsDisp[curImg]).stop().animate({height:imgHeight-0, width:imgWidth-0, opacity:.4}, 400, 'easeOutCirc', function()
            {
        centerCurImg(); 
    });

    curImg --;
    checkArrows();

}

function nextClickAdj()
{
    //$(imgsDisp[curImg]).stop().animate({height:imgHeight-0, width:imgWidth-0, opacity:.4}, 400, 'easeOutCirc', function()
            {
        centerCurImg(); 
    });

    curImg ++;
    checkArrows();  
}

function checkArrows()
{
    if ( curImg > 0 )  $('#prev-btn').show();
    else $('#prev-btn').hide(); 

    if ( curImg < imgs.length-1 )  $('#next-btn').show();
    else $('#next-btn').hide(); 
}

HTML

            <div id="imageContainer">

                <div class="container">

                    <div class="imageThumb"> 

                        <div class="imageFull"><img src="/images/newyork/img_1.jpg" /></div>

                    </div>

                    <div class="imageThumb"> 

                        <div class="imageFull"><img src="/images/newyork/img_2.jpg" /></div>

                    </div>

                    <div class="imageThumb"> 

                        <div class="imageFull"><img src="/images/newyork/img_3.jpg" /></div>

                    </div>

                    <div class="imageThumb"> 

                        <div class="imageFull"><img src="/images/newyork/img_1.jpg" /></div>

                    </div>

                    <div class="imageThumb"> 

                        <div class="imageFull"><img src="/images/newyork/img_2.jpg" /></div>

                    </div>

                    <div class="imageThumb"> 

                        <div class="imageFull"><img src="/images/newyork/img_3.jpg" /></div>

                    </div>

                </div>

            </div>



        <div id="prev-btn"><a href="#">Previous</a></div>

        <div id="next-btn"><a href="#">Next</a></div>

    </div>

ANY HELP WOULD BE APPRECIATED!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文