Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
907 views
in Technique[技术] by (71.8m points)

javascript - jquery-lazyload images in jquery-databables

With the datatables javascript plugin I want to display 10k little images in a table with pagination.
Because I load too much of them, I get errors.

I would like to load those images only when they appear so I found the lazyload plugin.

However, the images don't appear at all at first.
I have to manually enter

$("img.lazy").lazyload();

in the browser console.
Then only it loads the images that are on screen
(i.e. when I scroll down, I see all other images unloaded).
This proves at least that the plugin is somewhat working.

Is there something particular to do with the use of datatables?
Do I have to scriptually trigger lazyload every second?

Thank you !

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I found another method here without the lazyload plugin.
Use the option

"fnRowCallback": customFnRowCallback

and then this function will replace the first column with an image tag.

function customFnRowCallback( nRow, aData, iDisplayIndex )
{
    $('td:eq(0)', nRow).html( '<img class="" src="http://aaaaa/'+ aData.attribute+'" alt="" />' );
    return nRow;
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...