Working fiddle be here: http://jsfiddle.net/WyXLB/1/
When a HTML element contains multiple lines of text, I want to scan over each one. At the moment, I am just scanning over the bounding rectangle of the entire element.
Some code is :
function run_scan(el,mask,callback) {
// we need to go over each line of text in here
// or somewhere
var el_font_size = $(el).css('font');
$('body').append(sizer);
sizer.css({
'position': 'absolute',
'font' : el_font_size,
'white-space' : 'pre' } );
var real_box = window.getComputedStyle(sizer[0]);
var real_width = parseFloat(real_box.width);
var real_height = parseFloat(real_box.height);
var lines = Math.round($(el).height()/real_height);
var mask_offset = $(mask).offset();
var origin_left = mask_offset.left;
var duration = parseFloat($(mask).width())/2.0;
$(mask).animate( {
'left':origin_left+$(mask).width()
},
{
duration:duration,
complete:callback
} );
}
How can I break the animation over the entire bounding rectangle, to scan over each line. I tried putting an animation->callback recursion in the above function, descending the mask by one real_height each call, but got unpredictable/chaotic behavior.
If you need only loop then it should look like this (inside run_scan
)
var i = 0;
function loop() {
if (++i < lines) {
$(mask).animate({
'left':origin_left+$(mask).width()
},{
duration:duration,
complete:loop
});
} else {
// last line
callback();
}
}