html中ul折叠,html中ul标签的优化

  • Post author:
  • Post category:其他


对于前端的优化接触的太少了,平时在pc端上感觉正常,但是到了移动端,时间一长就不行了。今天说说html中ul的优化问题,我给出了一种传统的写法(耗时的),一种优化的写法.

模拟一种业务流程吧,类似留言墙,大家留言后,要将留言显示在留言墙上面。

开始我们的代码编写吧

如果在平时我会这样写,但是假如我接收了一百万条数据,代码如下:

没有进行性能优化的案例

var List = function(container,items,itemHeight){

this.container = container;

this.items = items;

this.itemHeight = itemHeight;

this.init();

this.update();

}

List.prototype.init = function(){

//创建一个ul

this.ul = document.createElement(“ul”);

this.ul.style.position = “relative”;

//将元素添加到div中

this.container.appendChild(this.ul);

}

List.prototype.update = function(){

for(var i = 0; i < this.items.length; i++){

var liTag = document.createElement(