Jquery插件在window.resize后停止正常工作,但在整页刷新后工作良好
Jquery plugin stops working correctly after window.resize, but works well after full page refresh
我正在我的页面中实现一个jquery轮播。因为我使用了百分比单位而不是固定单位,所以我需要在调整窗口大小后重绘轮播。
我的问题是轮播停止正常工作,其函数调用行为不正常,并且在使用以下代码调整大小后奇怪地呈现轮播:
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>
相关文章:
- 刷新后,setTimeout将工作或不工作
- .html()不会'页面更改或刷新时无法工作
- AngularJS控制器没有'第一次刷新页面后无法工作
- .addClass不工作(刷新时被删除)
- Javascript don'刷新页面后无法工作-为什么
- Kml层在刷新后工作正常,但给定typeError:无法读取属性getMap.第一次加载时
- jQuery AJAX刷新没有'不能在iPhone上工作
- Javascript在刷新后停止工作
- 页面刷新时脚本无法正常工作
- 为什么 jquery toggle() 方法在页面不刷新的情况下无法正常工作
- ngCookie在我刷新页面后无法正常工作
- Angular + requireJS:快速刷新页面会导致页面在 Chrome 中停止工作
- Jquery 日期选择器仅在页面刷新后工作
- 将公司名称绑定到更新面板中的下拉列表,自动完成文本框工作,但每次页面刷新时
- 防止刷新后返回不工作
- 轮播在初始重定向时中断,但在刷新时工作正常
- Javascript仅在第一次刷新后工作
- Javascript在页面刷新后工作,不知道解决方案
- JQuery 函数在页面加载时未触发,它仅在我刷新页面或再次重新访问同一页面后才能工作
- Rails 应用程序 - jQuery Document.ready在单击链接时不调用,但在新选项卡中打开或刷新时工作