Jquery slidershow 跨浏览器实现失败
这是我的图像滑块轮播的代码,该轮播设置为页面的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论