在DOM中有多少元素是如此糟糕? [英] Is it so bad to have heaps of elements in your DOM?

查看:127
本文介绍了在DOM中有多少元素是如此糟糕?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个房地产非交互式展示为他们的商店窗口



我踢了 jCarousel 做成我想要做的:


  • 为每个AJAX添加面板

  • 朝向当前设置的结束,去和AJAX一些新的面板,并插入它们



这工作正常,但它似乎调用jQuery的<$对先前元素的c $ c> remove()导致丑陋的凹凸。我不确定调用 hide()是否会释放任何资源,因为元素仍然存在(并且元素将不在屏幕上)。



我见过这个 a>,并在回调中尝试 carousel.reset()。它只是清除所有元素。



这将在Windows XP上的谷歌浏览器上运行,并且将仅在液晶电视上显示。



我在想,如果我不能找到一个合理的解决方案来移除额外的DOM元素,它是否会让我的应用程序被抓取,或者Chrome会做些什么垃圾收集?



或者,你怎么解决这个问题?



谢谢

解决方案

我制定了一个修复程序,结果非常简单!

<只需将它传递给jCarousel的配置

  itemFirstOutCallback:{
onAfterAnimation:function(carousel,li,index ,状态){
if(state ==='init')return;

carousel.remove(index);


$ b $ / code $ / pre

基本上,这只是删除列表元素一旦变为不可见(滚动到负值 overflow:hidden 地区,如果您愿意:))


I am making a real estate non interactive display for their shop window.

I have kicked jCarousel into doing what I want:

  • Add panels per AJAX
  • Towards the end of the current set, go and AJAX some new panels and insert them

This works fine, but it appears calling jQuery's remove() on the prior elements cause an ugly bump. I'm not sure if calling hide() will free up any resources, as the element will still exist (and the element will be off screen anyway).

I've seen this, and tried carousel.reset() from within a callback. It just clears out all the elements.

This will be running on Google Chrome on Windows XP, and will solely be displaying on LCD televisions.

I am wondering, if I can't find a reasonable solution to remove the extra DOM elements, will it bring my application to a crawl, or will Chrome do some clever garbage collecting?

Or, how would you solve this problem?

Thanks

解决方案

I worked out a fix that ended up being very simple!

Simply pass this to the config for jCarousel

itemFirstOutCallback: {
               onAfterAnimation: function(carousel, li, index, state) {
                 if (state === 'init') return;

                 carousel.remove(index); 

               }
            }

Basically, this just removes the list element as soon as it becomes invisible (scrolled into negative overflow: hidden territory, if you will :) )

这篇关于在DOM中有多少元素是如此糟糕?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆