jquery-lazyload images in jquery-databables

南笙酒味 提交于 2019-11-28 09:41:19

问题


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 !


回答1:


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;
}


来源:https://stackoverflow.com/questions/28816318/jquery-lazyload-images-in-jquery-databables

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!