thinking

front-end


  • Startseite

  • Archiv

  • Tags

reflow and repaint

Veröffentlicht am 2016-05-05

study reflow onceagain

Today I met with a problem about dynamic adding pictures with js.

1
2
3
4
5
6
7
<div id="main">
<div class="box">
<div class="pic">
<img src="img/{{index}}.jpg">
</div>
</div>
</div>

I want to add my pictures in “{index}”,so many that I can’t make many “div”s.I think of JS.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
//1get template
var _img=$("#main").innerHTML
.replace(/^\s*/,"")
.replace(/\s*$/,"");
//2 var
var out_img=[];
//3add data
for(var i in data){
var html_img=_img
.replace(/{{index}}/g,data[i].img);
out_img.push(html_img);
}
//4reflow
$("#main").innerHTML+=out_img.join("");


we all know that browser flows the “{index}” in html before meeting with JS.So our imgs package must have {index}.jpg

1…131415…22
Ipo

Ipo

Do one thing to the best

22 Artikel
20 Tags
© 2016 Ipo
Erstellt mit Hexo
Theme - NexT.Pisces