Javascript Jquery插件在window.resize之后停止正常工作,但在整个页面刷新之后工作良好
我正在我的页面中实现一个jquery旋转木马。因为我使用的是百分比单位而不是固定单位,所以需要在调整窗口大小后重新绘制旋转木马 我的问题是,旋转木马停止正常工作,其函数调用行为不正常,并在使用以下代码调整大小后奇怪地呈现旋转木马:Javascript Jquery插件在window.resize之后停止正常工作,但在整个页面刷新之后工作良好,javascript,jquery,window-resize,Javascript,Jquery,Window Resize,我正在我的页面中实现一个jquery旋转木马。因为我使用的是百分比单位而不是固定单位,所以需要在调整窗口大小后重新绘制旋转木马 我的问题是,旋转木马停止正常工作,其函数调用行为不正常,并在使用以下代码调整大小后奇怪地呈现旋转木马: jQuery(document).ready(function ($) { FnUpdateCarousel();
jQuery(document).ready(function ($) {
FnUpdateCarousel();
}); // end ready
var lightbox_resize = false;
$(window).resize(function() {
if (lightbox_resize)
clearTimeout(lightbox_resize);
lightbox_resize = setTimeout(function() {
FnUpdateCarousel();
}, 100);
});
function FnUpdateCarousel() {
var widthof =
Math.round(parseInt(jQuery('#services-example-1').css('width'))-(45));
jQuery('#services-example-1').services(
{
width:widthof,
height:290,
slideAmount:6,
slideSpacing:30,
touchenabled:"on",
mouseWheel:"on",
hoverAlpha:"off",
slideshow:3000,
hovereffect:"off"
});
};
请指导我如何使其正常运行。以下是我得出的解决方案:
<script type="text/javascript">
var initialContent = jQuery('#services-example-1').html();
jQuery(document).ready(function ($) {
FnUpdateCarousel();
}); // end ready
var lightbox_resize = false;
$(window).resize(function() {
if (lightbox_resize)
clearTimeout(lightbox_resize);
lightbox_resize = setTimeout(function() {
jQuery('#services-example-1').empty();
jQuery('#services-example-1').html(initialContent);
FnUpdateCarousel();
}, 200);
});
function FnUpdateCarousel() {
var widthof =
Math.round(parseInt(jQuery('#services-example-1').css('width'))-(45));
jQuery('#services-example-1').services(
{
width:widthof,
height:290,
slideAmount:6,
slideSpacing:30,
touchenabled:"on",
mouseWheel:"on",
hoverAlpha:"off",
slideshow:3000,
hovereffect:"off"
});
};
</script>
var initialContent=jQuery('#services-example-1').html();
jQuery(文档).ready(函数($){
FnUpdateCarousel();
}); // 准备就绪
var lightbox_resize=false;
$(窗口)。调整大小(函数(){
如果(灯箱大小)
clearTimeout(lightbox\u调整大小);
lightbox_resize=setTimeout(函数(){
jQuery('#services-example-1').empty();
jQuery('#services-example-1').html(initialContent);
FnUpdateCarousel();
}, 200);
});
函数FnUpdateCarousel(){
变量宽度=
Math.round(parseInt(jQuery('#services-example-1').css('width'))-(45));
jQuery('#services-example-1')。服务(
{
宽度:宽度,
身高:290,
幻灯片数量:6,
幻灯片间距:30,
touchenabled:“打开”,
鼠标滚轮:“打开”,
哈弗阿尔法:“关闭”,
幻灯片放映:3000,
悬停效果:“关闭”
});
};
我怀疑您不应该一次又一次地重新初始化整个旋转木马。如果您能更具体地了解您正在使用的jQuery插件,人们可能会更好地了解如何提供帮助。我建议查看文档,了解如何调整已经运行的旋转木马的大小。谢谢@jfriend00,仅供参考:这就是我正在集成的旋转木马。他们的文档看起来不是公开的,因此我们无法提供帮助。我想你需要研究一下文档,看看他们建议你如何调整它的大小。