lokesh / lightbox2

THE original Lightbox script (v2).
http://lokeshdhakar.com/projects/lightbox2/
MIT License
6.14k stars 1.77k forks source link

Cannot read property 'css' of undefined #669

Closed ghost closed 4 years ago

ghost commented 4 years ago

Lightbox v2.11.1

I'm using Jquery version 2.1.3, and also bootstrap 3.

when I open a modal window the first time. all right.

but when I close and open it again and click on the image, the following error appears:

Cannot read property 'css' of undefined

looking where the error originated, is here:

  // Position Lightbox
     var top = $window.scrollTop () + this.options.positionFromTop;
     var left = $window.scrollLeft ();
     this. $lightbox.css ({
       top: top + 'px',
       left: left + 'px'
     }).fadeIn(this.options.fadeDuration);

if I replace this. $ lightbox.css with $ (". lightbox") it works again, but other cascading errors begin to appear.

ghost commented 4 years ago

I was able to solve this problem simply by doing:

 $('.lightbox').remove ();

before creating the modal or when it is closed.

CrandellWS commented 3 years ago

was this fix not included in the current release?

cwolcott commented 3 years ago

Still having issues with this. Updated the code at line 97

Lightbox.prototype.build = function() {
    $('.lightbox').remove();  // Added code here based on above comment.
    if ($('#lightbox').length > 0) {
        return;
    }
r-interactive commented 6 months ago

I am getting the same issue when I open and close it. These are the errors:

1)

Uncaught TypeError: Cannot read properties of undefined (reading 'css') lightbox.js?ver=3be55b05081a63d8f9d0ecb466c42cfe:263 at Lightbox.start (lightbox.js?ver=3be55b05081a63d8f9d0ecb466c42cfe:263:20) at HTMLAnchorElement. (lightbox.js?ver=3be55b05081a63d8f9d0ecb466c42cfe:89:12) at HTMLBodyElement.dispatch (jquery.min.js?ver=3.7.1:2:40035) at v.handle (jquery.min.js?ver=3.7.1:2:38006)

2)

Uncaught TypeError: Cannot read properties of undefined (reading 'width') lightbox.js?ver=3be55b05081a63d8f9d0ecb466c42cfe:394 at lightbox.js?ver=3be55b05081a63d8f9d0ecb466c42cfe:394:10

I am using lightbox2 v2.11.4. Is there a way to fix this?