jQuery循环,100%宽度,图像垂直居中,窗口大小问题
html代码:jQuery循环,100%宽度,图像垂直居中,窗口大小问题,jquery,responsive-design,jquery-cycle,Jquery,Responsive Design,Jquery Cycle,html代码: <div id="rotatorholder"> <div id="slide1" class="slide"></div> <div id="slide2" class="slide"></div> <div id="slide3" class="slide"></div> </div> js代码: $('#rotatorholder').cycle({
<div id="rotatorholder">
<div id="slide1" class="slide"></div>
<div id="slide2" class="slide"></div>
<div id="slide3" class="slide"></div>
</div>
js代码:
$('#rotatorholder').cycle({
before: function () {
console.log($('#rotatorholder').width());
$("#rotatorholder div.slide").each(function () {
$(this).width($('#rotatorholder').width());
})
}
after: function () {
console.log($('#rotatorholder').width());
$("#rotatorholder div.slide").each(function () {
$(this).width($('#rotatorholder').width());
})
}
});
$(window).resize(function () {
var boxwidth = $('#rotatorholder').width();
$("#rotatorholder div.slide").each(function () {
$(this).width(boxwidth);
})
});
问题是:在调整浏览器窗口的大小之前,一切都很正常。之后,幻灯片元素将根据oryginal#rotatorholder宽度固定其宽度。我已经设法在调整窗口大小(第二个js部分)时固定了元素的宽度,元素也通过在jQuery循环调用中使用“before”获得了正确的新宽度,但仍然在一秒钟后,它们达到了它们的初始宽度
请访问:
使用较小的浏览器宽度运行它,然后将其重新缩放到更大的浏览器宽度。图像的“中心”仍应位于中心,并且正在调整大小,但当您停止调整大小并等待周期更改元素时,幻灯片的宽度会以某种方式变为初始容器宽度
谢谢你的帮助。Hmmmm。我使用的是Chrome v25,当我触发resize事件时,幻灯片元素会正确居中。你在用什么浏览器?Mac,chrome 25.0.1364.172。调整大小时,元素正确居中,但当您停止调整大小并等待循环更改幻灯片时,问题就会出现。
$('#rotatorholder').cycle({
before: function () {
console.log($('#rotatorholder').width());
$("#rotatorholder div.slide").each(function () {
$(this).width($('#rotatorholder').width());
})
}
after: function () {
console.log($('#rotatorholder').width());
$("#rotatorholder div.slide").each(function () {
$(this).width($('#rotatorholder').width());
})
}
});
$(window).resize(function () {
var boxwidth = $('#rotatorholder').width();
$("#rotatorholder div.slide").each(function () {
$(this).width(boxwidth);
})
});