Giter VIP home page Giter VIP logo

true-visibility's Introduction

true-visibility

Checks if a DOM element is truly visible

Usage

var my_element = document.getElementById('my-element');
//-- Returns true/false
my_element.isVisible(my_element);

true-visibility's People

Contributors

jasonfarrell avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

true-visibility's Issues

make this an HTMLElement property?

Having an all-caps global object is not particularly ideal. In this case, actually extending the HTMLElement prototype would be far better, so you can do document.querySelector(...).isVisible() and get a true/false value back

Won't work with nested scrolls

When using a nested scroll you'll probably get a wrong result.

I worked around the issue by comparing the boundary rectangles of the regular & scroll elements.

opacity: 0.00001

I think you could enhance your script by better testing the opacity property.
The only problem is setting an arbitrary limit for the opacity where you can't see the element anymore...

License for use?

I would like to use this as part of a test suite. There is no license on the repo. Can you establish an MIT licence on this repo so I can use this code?

Thanks

Suggestion: use a single repository for the visibility script

First of all: I like the concept, and the fact that this doesn't require any libs.

I think it would be nicer if the repo was actually named after the visibility script and contained only that. That would make it more findable (in both Github search and Google) and encourage interested people to fork and contribute. After all, it's unlikely that others will need the exact same set of js utils that you might eventually end up building if this repo expands.

Logic exactly backwards?

Isn't the logic for this line exactly backwards? Perhaps some of the other related checks too.

l + VISIBLE_PADDING > p.offsetWidth + p.scrollLeft ... return false;

...as l represents the el.offsetLeft and p is it's parent? For example, l in my code is about 950 (px), and p's left is around 600px.

In this case, the function isVisible should instead return true, affirming the checked el is visible given that el's left edge is a greater value (further to the right) than is the parent p (smaller value, closer to the left edge.)

I could understand if the function was isHidden. Am I missing something?

Problem with jshint

This while (element = element.parentNode) in _elementInDocument function is not accepted by jshint. It shows this error:

Expected a conditional expression and instead saw an assignment.

Can it be done this way:

function _elementInDocument(element) {
    while (true) {
        element = element.parentNode;
        if (element == document) {
            return true;
        }
    }
    return false;
}

False negatives/false positives

I am writing a password management tool that should only fill password fields if they are visible. On the following sites isVisible reports that password field are not visible, but they can be seen on the page:

linkedin.com, wordpress.com, outbrain.com, amazonaws.com, hulu.com, wikihow.com, webmd.com

On none of these sites is the password field in an iframe. In most but not all of these cases, the problem is with the overlap test.

On fiverr.com isVisible reports that password fields are visible when they can't be seen on page.

Consider this SO post

There are probably useful ideas and/or code posted here that could enhance the visibility script's functionality.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.