我正在尝试在一个带有jQuery幻灯片的页面上运行JavaScript窗口调整脚本,但我遇到了一些无法解决的错误。它可以在页面加载时很好地调整第一张图片的大小,但随后的幻灯片会忘记新的高度/宽度属性。我可以在使用jQuery之前和之后再次设置这些属性,但图像始终会在调整大小之前以全尺寸闪烁一小段时间。
jQuery.cycle是否将幻灯片调整回其原生大小?如果是,我该如何停止这个过程?
$(document).ready(function () {
$('.slideshow').cycle({
fx: 'fade',
speed: 200,
timeout: 1000,
pause: 1,
before: function (currSlideElement, nextSlideElement, options, forwardFlag) {
resize();
},
after: function (currSlideElement, nextSlideElement, options, forwardFlag) {
resize();
}
});
$('.slideshow').find('img').css("height", "0");
$('#image').hide().idle(1000).fadeIn();
resize();
});
$(window).resize(function () {
resize();
});
function resize() {
var theheight = window.innerHeight;
var thewidth = window.innerWidth;
var imageheight = theheight - 200;
if (imageheight > 540) {
imageheight = 540;
}
if (imageheight < 300) {
imageheight = 300;
}
var imagewidth = imageheight / 0.6585365;
$(".slide").css("height", imageheight);
$(".slide").css("width", imagewidth);
$(".slide").attr("height", imageheight);
$(".slide").attr("width", imagewidth);
}