Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separate loaded check for custom load() function. #274

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

doiftrue
Copy link

@doiftrue doiftrue commented Oct 13, 2021

To illustrate the problem, let me give you an example.

Suppose we have an HTML element:

<div class="lozad animation" data-background-image="URL">
    some html
</div>

Now lets hang two lozad call on the one element:

// first default call
lozad().observe()

// second - custom call
const el = document.querySelector('.animation')
lozad( el, {
    load: function(){
        // some code for animation
    }
} ).observe() 

For both of these calls the same check is triggered to see if the lozad already loaded. So only the first call will work, and on the second call lozad will see that it is already done and just skip execution of our custom function.

Also!

It is betted to specify the unique name for the data-loaded html attribute, bacause it is a rather common name that can be used by another script and if that happens we catch unpredictable conflict. Therefore, it is better to give a more unique name, such as data-lozaded.

…ified.

Unique HTML data attribute name, which contains data that lozad loaded: from `data-loaded` to `data-lozaded`.
@doiftrue doiftrue marked this pull request as ready for review October 13, 2021 16:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant