I'm making some kind of movie with a webpage. For that I have to do certain things with the chars of the text. The html looks like this:
<div id="section_1" style="display: none;">
<p>Goede typografie stimuleert het lezen en heeft als gevolg dat men zo weinig mogelijk moeite hoeft te doen om een tekst te kunnen lezen. Het moet zo min mogelijk weerstand oproepen om een tekst te kunnen begrijpen.</p>
</div>
<div id="section_2" style="display: none;">
<p>Het vermogen om zeer snel te kunnen lezen en zodoende onze tijd effectief te kunnen gebruiken, hangt vooral af van de wijze waarop de boodschap typografisch is vormgegeven.</p>
</div>
To use the chars, I span every letter. Shown below:
var spans = new Array();
// span every character
for(var i = 0; i < data.sections.length; i++) {
//spanEachChar("#section_"+i);
$("#section_"+i).children().andSelf().contents().each(function(index){
if (this.nodeType == 3) {
var $this = $(this);
$this.replaceWith($this.text().replace(/\w/g, function(text,index2) {
return "<span id="+index2+">" + text + "</span>";
}));
}
});
}
// store each span in an array
$("#content span").each(function() {
spans.push($(this));
});
console.log("spans.length "+spans.length);
// get them like this
var span = spans[20];
I also have a array/object (don't know what it's called) where I store the duration for each section so it shows the new one after a certain time.
var data = {
sections:[{
id: 0,
duration: 0,
firstSpanIndex: -1,
lastSpanIndex: -1
}, {
id: 1,
duration: 7,
firstSpanIndex: -1,
lastSpanIndex: -1
}, {
id: 2,
duration: 7,
firstSpanIndex: -1,
lastSpanIndex: -1
}]
}
There is the array named spans, shown above, for each div for example in 'section_2', I want to store the firstSpanIndex and the last lastSpanIndex. I think this maybe can be done at the part where I span every character but i wouldn't know how.
I hope you guys understand my question, it's not that easy to explain.
update
Thanks for the help so far. It's helpfull for the purpose of learning but not really what i wanted. I made a image to make more clear what i want.

I hope the image is clear enough. It shows 4 paragraps split up in spans for each char. All those spans are in one array. Nothing more in that array (so no first or last). Then the data.sections hold's info for each paragraph, like the id (equal to the index atm) and how many seconds it should show up (not show in the image) and the start and end index of the span array.