grumble.js,jQuery 插件(气泡弹出窗口):如何使其不被不可移动的垃圾污染我的文档正文?
我想在点击时显示一个弹出窗口。我希望很多人都处于泡沫之中。所以我创建了一个演示:此处。但是我使用的 气泡生成器插件 每次显示时都会在 DOM 中保留大量垃圾弹出窗口。好吧,所以我试图通过销毁垃圾
$('.grumble-text').remove();
$('.grumble').remove();
$('.grumble-button').remove();
,但它以某种方式完全阻止了它=( 那么如何更改 grumble-bubble弹出插件代码以使其保持 DOM 干净或至少使插件独立于它创建的垃圾?
I want to show a popup many on click. I want that many to be in a bubble. So I created a demo: here. But that Bubble generator plugin i use tends to keep tons of trash in the DOM each time it shows a popup. Well so I tried to destroy trash via
$('.grumble-text').remove();
$('.grumble').remove();
$('.grumble-button').remove();
But it somehow brakes it at all=( So how to change grumble-bubble popup plugin code to make it either keep DOM clean or at least make plugin independent of trash it creates?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
为什么要删除它? “垃圾”是否会导致浏览器性能出现问题?
一般来说,执行此操作的唯一方法是深入研究插件源并添加一个功能来删除插件(如果尚不存在)。如果您只是删除相关的 DOM 元素,您将留下对它们的引用以及访问它们的事件处理程序。
Why do you want to remove it? Is the 'trash' causing problems with browser performance?
In general, the only way to do this is to dig into the plugin source and add a function to remove the plugin, if one is not already present. If you just remove the related DOM elements you will leave behind references to them and events handlers that access them.
在
onHide
回调中使用grumble
和button
参数,如下所示:这允许您仅删除“垃圾”(我更喜欢“剩菜”) )与特定的工具提示/弹出窗口/气泡关联。请注意,仅当
hasHideButton
为true
时,button
才存在,因此要进行button &&
存在检查。Use the
grumble
andbutton
parameters on theonHide
callback like this:This allows you to remove only the "trash" (I prefer "leftovers") associated with that specific tooltip/popup/bubble. Note that
button
only exists ifhasHideButton
istrue
, hence thebutton &&
existence check.我最近更新了该插件,以提供更好的定位和角度控制。更新还保留了抱怨,在一个元素上多次调用插件不会创建额外的剩余 DOM。
尝试更新到最新的代码。下面的代码现在应该可以按您的预期工作。
感谢您的关注。如果还有任何其他问题,请在 github 页面上将其作为错误提出。 https://github.com/jamescryer/grumble.js
I've recently updated the plugin to provide better control of positioning and angle. The update also persists the grumble, invoking the plugin more than once on an element will not create extra left over DOM.
Try updating to the latest code. The code below should now work as you expect.
Thanks for your interest. If there are any further problems please raise them as bugs on the github page. https://github.com/jamescryer/grumble.js