比如一个屏幕的高度一般是800像素左右,假设一条记录占用的高度是20像素,我们只用创建40个对象即可。
接下来就是对这40个对象进行数据填充,通过滚动条调整填充数据的起始下标。
10W条记录,IE下有些卡
<style type="text/css">
.panel{
overflow:scroll
width:200px
height:80%
}
.panel .scroll{
}
.item{
width:500px
height:20px
}
.odd{
background-color:#ccc
}
.items{
overflow:hidden
position:absolute
}
.red{
color:red
}
.green{
color:green
}
</style>
<script>
window.console = window.console || { log: function() {} }
function absolutePoint(element) {
var result = [element.offsetLeft, element.offsetTop]
element = element.offsetParent
while (element) {
result[0] += element.offsetLeft
result[1] += element.offsetTop
element = element.offsetParent
}
return result
}
function ListView(options){
options = options || {}
var self = this,
$C = function(tagName) { return document.createElement(tagName)}, // 创建节点
p,
height,
item_height, // 项高
view_count, // 可见项条数
parent = options.parent || document.body, // 容器
height, // 面板历史高度
div_panel = $C("div"),
div_scroll = $C("div"),
div_items = $C("div"),
div_items_list = [$C("div")],
freed = [div_panel, div_scroll, div_items]// 可释放的对象
div_panel.className = "panel"
parent.appendChild(div_panel)
div_items.className = "items"
document.body.appendChild(div_items)
div_scroll.className = "scroll"
div_panel.appendChild(div_scroll)
div_panel.onscroll = function() {
doChange()
}
div_panel.onresize = function() {
doChange()
}
div_items_list[0].className = "item"
div_items.appendChild(div_items_list[0])
div_scroll.style.width = div_items_list[0].clientWidth + "px"
item_height = div_items_list[0].clientHeight
p = absolutePoint(div_panel)
with(div_items.style) {
left = p[0] + "px"
top = p[1] + "px"
width = div_panel.clientWidth
height = div_panel.clientHeight
}
/**
* 界面改变
*/
function doChange() {
if (!item_height) return
var i, div
if (height != div_panel.clientHeight) {
height = div_panel.clientHeight
view_count = parseInt(height / item_height)
for (i = div_items_list.lengthi <view_counti++) {
div = $C("div")
div.className = "item" + (i % 2 == 0 ? "" : " odd")
div_items.appendChild(div)
div_items_list.push(div)
}
for (i = 0i <div_items_list.lengthi++) {
div_items_list[i].style.display = i <view_count ? "" : "none"
}
div_scroll.style.height = div_panel.clientHeight + options.count - view_count + "px"
console.log(["view_count", view_count])
}
div_items.scrollLeft = div_panel.scrollLeft
if (!options.ondrawitem) return
i = Math.min(view_count, div_items_list.length)
while(i--) {
// 重新绘制
options.ondrawitem(i + div_panel.scrollTop, div_items_list[i])
}
}
doChange()
this.doChange = doChange
/**
* 释放Dom对象
*/
this.dispose = function() {
var i = freed.length
while(i--) {
freed[i].parentNode.removeChild(freed[i])
}
i = freed.length
while(i--) {
div_items_list[i].parentNode.removeChild(div_items_list[i])
}
}
}
function format(template, json) {
if (!json) return template
return template &&template.replace(/\$\{(.+?)\}/g, function() {
return json[arguments[1]]
})
}
window.onload = function() {
var i = 100000, data = new Array(i)
while(i--) {
data[i] = { index: i, random: Math.random(), key: (+new Date()).toString(36) }
}
var listview = new ListView({
count: data.length,
ondrawitem: function(i, div) {
div.innerHTML = format(" <em>${index} </em> <span class=\"red\">${random} </span> <span class=\"green\">${key} </span>", data[i])
}
})
}
</script>
qq三国100js1万用灼伤的奥义。其实用什么技能有很大的主观性,有的技能不实用,可有人觉得好看,就是喜欢用它。
比如55技能和25技能,都是群功,55技能明显好看很多,一个“灭”字感觉很帅,但是用的人还是少。
80技能取代40是没问题的,60技能也能取代40,70技能主要还是加负面状态。