I have static image 500x640 sitting in folder catted by 20x20 pieces with css sprites, I am setting background-position to display each piece, I need such kind of display to be able to manipulate with each piece later.
css:
.piece
{
width: 20px;
height: 20px;
display: inline-block;
//display: inline;
//zoom:1;
}
.ob { background-image: url("/Images/ob.jpg");}
js:
<script id="flipTemplate" type="text/html">
<div class="piece ob" data-bind="style: { backgroundPosition: viewModel.getLeftValue($index) + ' ' + viewModel.getTopValue($index) }, attr: {cond: Cond, id: Id }, click: viewModel.setClick ">
</div>
</script>
<script type="text/javascript">
viewModel = {
flips: ko.observableArray([]),
setClick: function (data, e) {
e.preventDefault();
//doing click
},
getLeftValue: function (index) {
var position = 0;
var currentLine = div(index(), 25);
if (currentLine > 0)
return '-' + (index() - (currentLine * 25)) * 20 + 'px';
else
return '-' + index() * 20 + 'px';
},
getTopValue: function (index) {
return '-' + (div(index(), 25)) * 20 + 'px';
}
};
ko.applyBindings(viewModel);
</script>
function div(val, by){
return (val - val % by) / by;
}
So am having some performance issues. For example in Opera and FF images loading very quickly about 1 sec, in IE about 3 sec, but in Chrome it is loading very slow
it is taking about 17 sec to display all pieces in Chrome...
Browser doing just one request to get the image and than cutting small pieces from it, why it may take so long in Chrome?
Is there any way i can improve performance?
just did CTRL+Refresh and here strange loading result:
UPDATE: I just placed a sample here: http://bit.ly/TrcCdp
UPDATE: In my sample there is JSON array, it is contains 800 elements, so I just find out if I make it less, eg 600-700 elements the performance is getting better, but I need 800 elements anyway.
e.g When there is only 600 elements it is reducing the load in Chrome to about 6 sec....
So probably may be the problem somewhere at the point where knockout iterating template?
display:none
. – Opprobrium