Skip to content

Instantly share code, notes, and snippets.

@jheimbach
Last active January 4, 2016 19:20
Show Gist options
  • Select an option

  • Save jheimbach/8667068 to your computer and use it in GitHub Desktop.

Select an option

Save jheimbach/8667068 to your computer and use it in GitHub Desktop.
Simple Lightbox in Coffeescript
class Lightbox
setStructure: ->
lightbox = '<div id="lightbox">' +
'<div id="lightbox_content">' +
'<a class="close_lightbox" href="javascript:void(0)">Schließen</a>' +
'<div class="lightbox_text"></div> ' +
'</div>' +
'</div>';
$('body').append(lightbox)
return
showLightbox: (data)->
$('.lightbox_text').first().html(data);
$('#lightbox').show();
lightboxcontentHeight = parseInt($('#lightbox_content').height()) + parseInt($('#lightbox_content').css('margin-top').replace('px',''))
if lightboxcontentHeight >= $(window).height()
$('#lightbox').height(window.document.height)
$('#lightbox').addClass('long')
window.scrollTo(0,0)
hideLightbox: ()->
$('#lightbox').hide()
#lightbox {
top: 0;
left: 0;
width: 100%;
height: 100%;
position: fixed;
background: rgba(0, 0, 0, 0.71);
}
#lightbox.long {
position: absolute;
}
.close_lightbox {
width: 27px;
top: -13.5px;
right: -11px;
height: 22px;
display: block;
position: absolute;
background-repeat: no-repeat;
background-image: url('img/close.png');
}
#lightbox_content {
padding: 40px;
max-width: 60%;
margin: 40px auto;
background: white;
position: relative;
margin-top: 40px !important;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment