HTMLGuyLLC / jAlert

jQuery alert/modal/lightbox plugin
https://htmlguyllc.github.io/jAlert/
MIT License
76 stars 35 forks source link

possible bug in javascript: viewportHeight #59

Closed claudioimai closed 6 years ago

claudioimai commented 6 years ago

Just found this problem, in a window larger the the viewport, with a lightbox opening far below the viewport, rendering it useless. (in Firefox 59, at least)

I found this code on line 97:

    var viewportHeight = $(window).height(),
    alertHeight    = alert.instance.height(),
    diff           = viewportHeight - alertHeight;

Fix: $(window).height() returns the full height of the rendered page, while the code wants the viewport size.

I switched it to

    var viewportHeight = window.innerHeight,
        alertHeight    = alert.instance.height(),
        diff           = viewportHeight - alertHeight;

window.innerHeight will correctly return the viewport height, thus positioning the window at the correct place.

HTMLGuyLLC commented 6 years ago

This is potentially a real fix, but I'd like someone to confirm browser compatibility before I merge.

HTMLGuyLLC commented 6 years ago

Latest version implements something like this. It was done to improve layout for larger alerts that are taller than the window which was causing them to be too close to the top of the window.