Skip to content

Instantly share code, notes, and snippets.

@maxterry
Last active February 28, 2016 17:31
Show Gist options
  • Select an option

  • Save maxterry/464fdbaa4b6ec2260414 to your computer and use it in GitHub Desktop.

Select an option

Save maxterry/464fdbaa4b6ec2260414 to your computer and use it in GitHub Desktop.

Revisions

  1. maxterry revised this gist Feb 28, 2016. 2 changed files with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions lightbox
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    Simple Lightbox (modal window with semi-transparent background)
    Binary file modified bg.png
    Loading
    Sorry, something went wrong. Reload?
    Sorry, we cannot display this file.
    Sorry, this file is invalid so it cannot be displayed.
  2. maxterry created this gist Feb 28, 2016.
    Binary file added bg.png
    Loading
    Sorry, something went wrong. Reload?
    Sorry, we cannot display this file.
    Sorry, this file is invalid so it cannot be displayed.
    15 changes: 15 additions & 0 deletions lightbox.css
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    #lightboxContainer {
    display: none;
    position: absolute; top: 0; height: 100%; width: 100%; z-index: 1;
    background: url(/img/bg.png);
    }

    #lightbox {
    display: none;
    z-index: 2;
    margin-top: 135px;
    margin-left: auto; margin-right: auto;
    height: 50%; width: 50%;
    min-height: 200px; min-width: 200px;
    background: #fff;
    }
    9 changes: 9 additions & 0 deletions lightbox.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,9 @@
    <div id="lightboxContainer">
    <div id="lightbox">
    <div>
    <div>
    Lightbox
    </div>
    </div>
    </div>
    </div>
    22 changes: 22 additions & 0 deletions lightbox.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    function showLightbox() {
    // Semi-transparent background
    document.getElementById('lightboxContainer').style.display = 'block'
    // Dialog box
    document.getElementById('lightbox').style.display = 'block'
    // Prevent scrolling
    document.body.style.overflow = 'hidden'
    // Set Esc button listener, to close lightbox
    document.onkeydown = function(ev) {
    ev = ev || window.event
    if (ev.keyCode == 27) {
    hideLightbox()
    }
    }
    }

    function hideLightbox() {
    document.getElementById('lightboxContainer').style.display = 'none'
    document.getElementById('lightbox').style.display = 'none'
    document.body.style.overflow = 'auto'
    document.keydown = null
    }