Skip to content

Commit 2143612

Browse files
committed
Add border to image.
1 parent 363c3cb commit 2143612

File tree

2 files changed

+27
-15
lines changed

2 files changed

+27
-15
lines changed

src/css/lightbox.css

+7-5
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ body.lb-disable-scrolling {
3535
max-width: inherit;
3636
max-height: none;
3737
border-radius: 3px;
38+
39+
/* Image border */
40+
border: 4px solid white;
3841
}
3942

4043
.lightbox a img {
@@ -43,12 +46,15 @@ body.lb-disable-scrolling {
4346

4447
.lb-outerContainer {
4548
position: relative;
46-
background-color: white;
4749
*zoom: 1;
4850
width: 250px;
4951
height: 250px;
5052
margin: 0 auto;
5153
border-radius: 4px;
54+
55+
/* Background color behind image.
56+
This is visible during transitions. */
57+
background-color: white;
5258
}
5359

5460
.lb-outerContainer:after {
@@ -57,10 +63,6 @@ body.lb-disable-scrolling {
5763
clear: both;
5864
}
5965

60-
.lb-container {
61-
padding: 4px;
62-
}
63-
6466
.lb-loader {
6567
position: absolute;
6668
top: 43%;

src/js/lightbox.js

+20-10
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@
7373
var self = this;
7474
// Both enable and build methods require the body tag to be in the DOM.
7575
$(document).ready(function() {
76-
self.enable();
77-
self.build();
76+
self.enable();
77+
self.build();
7878
});
7979
};
8080

@@ -99,13 +99,23 @@
9999
this.$overlay = $('#lightboxOverlay');
100100
this.$outerContainer = this.$lightbox.find('.lb-outerContainer');
101101
this.$container = this.$lightbox.find('.lb-container');
102+
this.$image = this.$lightbox.find('.lb-image');
102103
this.$nav = this.$lightbox.find('.lb-nav')
103104

104105
// Store css values for future lookup
105-
this.containerTopPadding = parseInt(this.$container.css('padding-top'), 10);
106-
this.containerRightPadding = parseInt(this.$container.css('padding-right'), 10);
107-
this.containerBottomPadding = parseInt(this.$container.css('padding-bottom'), 10);
108-
this.containerLeftPadding = parseInt(this.$container.css('padding-left'), 10);
106+
this.containerPadding = {
107+
top: parseInt(this.$container.css('padding-top'), 10),
108+
right: parseInt(this.$container.css('padding-right'), 10),
109+
bottom: parseInt(this.$container.css('padding-bottom'), 10),
110+
left: parseInt(this.$container.css('padding-left'), 10)
111+
};
112+
113+
this.imageBorderWidth = {
114+
top: parseInt(this.$image.css('border-top-width'), 10),
115+
right: parseInt(this.$image.css('border-right-width'), 10),
116+
bottom: parseInt(this.$image.css('border-bottom-width'), 10),
117+
left: parseInt(this.$image.css('border-left-width'), 10)
118+
};
109119

110120
// Attach event handlers to the newly minted DOM elements
111121
this.$overlay.hide().on('click', function() {
@@ -282,8 +292,8 @@
282292

283293
windowWidth = $(window).width();
284294
windowHeight = $(window).height();
285-
maxImageWidth = windowWidth - self.containerLeftPadding - self.containerRightPadding - 20;
286-
maxImageHeight = windowHeight - self.containerTopPadding - self.containerBottomPadding - 120;
295+
maxImageWidth = windowWidth - self.containerPadding.left - self.containerPadding.right - self.imageBorderWidth.left - self.imageBorderWidth.right - 20;
296+
maxImageHeight = windowHeight - self.containerPadding.top - self.containerPadding.bottom - self.imageBorderWidth.top - self.imageBorderWidth.bottom - 120;
287297

288298
// Check if image size is larger then maxWidth|maxHeight in settings
289299
if (self.options.maxWidth && self.options.maxWidth < maxImageWidth) {
@@ -328,8 +338,8 @@
328338

329339
var oldWidth = this.$outerContainer.outerWidth();
330340
var oldHeight = this.$outerContainer.outerHeight();
331-
var newWidth = imageWidth + this.containerLeftPadding + this.containerRightPadding;
332-
var newHeight = imageHeight + this.containerTopPadding + this.containerBottomPadding;
341+
var newWidth = imageWidth + this.containerPadding.left + this.containerPadding.right + this.imageBorderWidth.left + this.imageBorderWidth.right;
342+
var newHeight = imageHeight + this.containerPadding.top + this.containerPadding.bottom + this.imageBorderWidth.top + this.imageBorderWidth.bottom;
333343

334344
function postResize() {
335345
self.$lightbox.find('.lb-dataContainer').width(newWidth);

0 commit comments

Comments
 (0)