jCarousel 卸载/禁用/删除
我正在使用 jCarousel 在我的页面中显示图像轮播。它工作得很好并且没有任何抱怨,但是我正在使用页面上的选项卡,当我转到另一个选项卡时,它会出现一个丑陋的 jCarousel 错误。基本上我想做的是当我转到新选项卡时从我的元素中删除jCarousel,但我一生都无法弄清楚
要添加轮播我正在使用这样的代码 $("#myelement"). jCarousel({ /* 配置参数 */});
但我不确定如何从 $("#myelement") 中删除 .jCarousel 有什么想法吗?
I am using jCarousel to have a carousel of images in my page. It works great and have no complaints, but I am using the tabbing on the page and when I goto another tab, it get an ugly jCarousel error. Basically what I want to do is to remove the jCarousel from my element when I goto a new tab but for the life of me can't figure it out
To add the carousel I am using code like this $("#myelement").jCarousel({ /* config params */});
But I am unsure of how to remove .jCarousel from $("#myelement") any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
除了 PaDalton 的回答之外,我还从窗口中分离了调整大小事件,因为我的轮播位于 (colorbox ) 弹出框。
当事件被触发时,
$(this).dimensions(e)
行发送警报消息,因为li节点没有大小,它认为要显示对象但没有大小将无法正确计算轮播尺寸。错误消息为
无限循环 - 未设置宽度或高度
In addition to PaDalton's answer, I also detached the resize event from the window as my carousel was inside a (colorbox) popup box.
When the event got triggered, the
$(this).dimensions(e)
line sent the alert message as the li node didn't have a size, it thought the the object was to be displayed but without a size it would not be able to compute the carousel dimensions properly.The error message was
Infinite Loop - no width or height set
这是我删除元素并且不出现错误的方法:
当我们单击主区域中的链接时,
我的 jCarousel 元素将从另一个脚本中删除,因此
我们有一个处理程序来处理这个女巫,它正在停止旋转木马,然后 .remove 。
我尝试在回调之外执行此操作,但似乎 jCarousel
只能从回调内部控制。
Here is my way to remove the element and not get an error:
when we click on a link in the mainarea,
my jCarousel element will be removed from another script so
we have a handler for this witch is stopping the carousel and than .remove .
I've tried to do this outside the callback but it seams that the jCarousel
is only controllable from inside the callback.
这是我对这个丑陋的 js 错误“Jcarousel:没有为项目设置宽度/高度...”的解决方案。尽量避免 jCarousel 的双重初始化。
或者尝试获取 jCarousel 的实例,例如
如果您通过 AJAX 替换 jCarousel 容器,您应该执行如下操作:
我希望这可以帮助某人...
schulle7
Here is my solution for this ugly js error "Jcarousel: No width/height set for items ...". Try to avoid double initialization of jCarousel.
Or try to get an instance of jCarousel like
If you replace the jCarousel container via AJAX you should do something like this:
I hope this helps someone...
schulle7
我假设您正在谈论这个插件: http://sorgalla.com/jcarousel/
什么类型你收到错误了吗?我猜它试图找到不可见且失败的元素。看起来您只需将一个函数绑定到选项卡切换即可隐藏轮播或调用其 Reset() 方法。
I'm assuming you're talking about this plugin: http://sorgalla.com/jcarousel/
What type of error are you getting? I'm guessing it's trying to find elements that aren't visible and failing. It'd seem like you could just bind a function to the tab switching to either hide the carousel or call its reset() method.