8000 Problem with detecting if element is inView · Issue #35 · dinbror/blazy · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Problem with detecting if element is inView #35
Closed
@karooolis

Description

@karooolis

On my website I have been experiencing a problem with the script where it doesn't detect correctly whether an element is in view or not. It's because some images on my website ( bredymer.dk/biler.aspx ) return ele.getBoundingClientRect().left value less than zero meaning that their left coordinate starts outside viewport. This has caused some of the images not to load and I fixed it by

I have fixed it by modifying

    function elementInView(ele) {
        var rect = ele.getBoundingClientRect();
        var bottomline = winHeight + options.offset;

        return (
         // inside horizontal view
         rect.left >= -20
         && rect.right <= winWidth + options.offset  
         && (
         // from top to bottom
         rect.top  >= 0
         && rect.top  <= bottomline
         // from bottom to top
         || rect.bottom <= bottomline
            && rect.bottom >= 0 - options.offset
            )
        );

  
4CF5
      return inView;
     }

where I set rect.left >= -20 . This is not a universal solution and only helped fixed problem in my website. Perhaps there are some universal ways to solve it?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0