Skip to content

Instantly share code, notes, and snippets.

@vladkras
Last active December 17, 2015 03:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vladkras/5546943 to your computer and use it in GitHub Desktop.
Save vladkras/5546943 to your computer and use it in GitHub Desktop.
aRise - simple lightbox, fancybox & other gallery popups alternative. All in one file: no css and image files for controls. Only jQuery needed.
(function($) {
"use strict";
$.fn.aRise = function() {
// vars first of all
var links = this, total = this.length;
// add styles to head
$('head').append('<style type="text/css">#arise-div{position:absolute;top:20%;left:50%;cursor:pointer;background-color:#fff;border:1px #aaa solid;padding:2px 4px;border-radius:4px;}</style>');
links.each(function(index) {
$(this).click(function(e) {
e.preventDefault();
// update index value
index = $(this).index();
// remove if already opened
$('#arise-div').remove();
// inner content of popup
var ariseDivOptions = {
id: "arise-div",
html: "<img id='' src='" + $(this).attr("href") + "' alt='" + $(this).attr("title") + "' />"
};
// include title (if any)
if ($(this).attr("title")) ariseDivOptions.html = "<div class='title'>" + $(this).attr("title") + "</div>" + ariseDivOptions.html;
// create aRise popup
var ariseDiv = $("<div/>", ariseDivOptions).appendTo("body").css("margin-left", "-" + ariseDiv.find('img').width() / 2 + "px");
// close popup when clicked outside it
$(document).mouseup(function (e) {
if (!ariseDiv.is(e.target) && ariseDiv.has(e.target).length === 0) ariseDiv.hide();
});
ariseDiv.click(function() {
index = ( index == total - 1 ) ? 0 : index+1;
var $this = $(this), next_href = $(links[index]).attr("href"), next_title = $(links[index]).attr("title");
$this.find('img').attr("src",next_href);
$this.find('.title').html(next_title);
$this.css("margin-left", "-" + $this.find('img').width() / 2 + "px");
});
});
});
}
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment