Last active
December 17, 2015 03:58
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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