我需要克隆一个元素,一旦调整页面大小,就会覆盖那里的当前元素。
我当前的代码不起作用,如下所示:
var clone = false;
window.addEvent("domready",function(){
clone = $$('.view').clone();
/* Wait for images to be 100% loaded otherwise they might not have width/height */
var lazyloader = new LazyLoad({
onComplete: function(){
setupWall();
window.addEvent('resize:throttle(1000)', function(){
/* Delete old viewport and add back with cloned version */
var view = $$('.view');
if(view){
wall = null;
view.dispose();
}
var cloneElement = $$('#wrapper').inject(clone);
console.log(cloneElement);
//setupWall();
});
}
});
});
运行时$$('#wrapper').inject(clone);
出现以下错误:
无法调用 null 的方法“appendChild”
正如这里的评论中所建议的那样,html也是如此。
<div id="wrapper">
<section class="view" id="wall">
<div class="panel" id="panel1"><img src="_assets/images/loading.gif" data-src="http://placekitten.com/701/310" /></div>
<div class="panel" id="panel2"><img src="_assets/images/loading.gif" data-src="http://placekitten.com/702/320" /></div>
<div class="panel" id="panel3"><img src="_assets/images/loading.gif" data-src="http://placekitten.com/703/330" /></div>
<div class="panel" id="panel4"><img src="_assets/images/loading.gif" data-src="http://placekitten.com/704/340" /></div>
<div class="panel" id="panel5"><img src="_assets/images/loading.gif" data-src="http://placekitten.com/705/350" /></div>
<div class="panel" id="panel6"><img src="_assets/images/loading.gif" data-src="http://placekitten.com/706/360" /></div>
<div class="panel" id="panel7"><img src="_assets/images/loading.gif" data-src="http://placekitten.com/707/370" /></div>
<div class="panel" id="panel8"><img src="_assets/images/loading.gif" data-src="http://placekitten.com/708/380" /></div>
<div class="panel" id="panel9"><img src="_assets/images/loading.gif" data-src="http://placekitten.com/709/390" /></div>
<div class="panel" id="panel10"><img src="_assets/images/loading.gif" data-src="http://placekitten.com/710/400" /></div>
<div class="panel" id="panel11"><img src="_assets/images/loading.gif" data-src="http://placekitten.com/711/410" /></div>
</section>
</div>