dinbror/blazy

.load() doesn't work.

wdews opened this issue · 5 comments

wdews commented

Looks like the code the .load() function references is faulty. "loadImage()" simply doesn't work. At all. It's also unclear whether you pass it a jQuery object or a native DOM element. I've tried both, doesn't work with either.

Hey.

That sounds odd. Do you have a live example? How're you using it? Show code or it didn't happend ;)

@wdews If you read the introduction it says it's NOT a jQuery plugin, this would force me to assume an HTML element is expected.

Eworm commented

I have the same question. It doesn't matter if I use:

bLazy.load(document.getElementsByClassName('highlight-item-img'), true);
or
bLazy.load($('.highlight-item-img'), true);

I always get the same error message:
Uncaught TypeError: i.getAttribute is not a function

@Eworm

document.getElementsByClassName('highlight-item-img')
// [div.highlight-item-img]

returns an array even if its only one element

If you try

document.getElementsByClassName('highlight-item-img')[0]
// div.highlight-item-img

You need to pass in one element.

If you read the source you can see the function expects only ONE element.

Blazy.prototype.load = function(element, force){
    if(!isElementLoaded(element)) loadImage(element, force);
};

I would suggest that the script have a type check somewhere to prevent this error although it is very straight forward.

Fixed in v. 1.5.0, now you can pass a single element, a list of elements or jquery elements