Skip to content

Instantly share code, notes, and snippets.

@rbarros
Created May 24, 2012 13:35
Show Gist options
  • Save rbarros/2781580 to your computer and use it in GitHub Desktop.
Save rbarros/2781580 to your computer and use it in GitHub Desktop.
Popup javascript
/*!
* PopUp JavaScript Plugin v0.8.12
* http://public.ramon-barros.com/
*
* Copyright (c) 2012 Ramon Barros and other contributors,
* http://ramon-barros.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*
* Date: Wed Aug 01 15:21:00 2012 -0300
*/
var popup = {
img:'',
img_close:'www/popup/img/close.png',
style:'',
config:function(){
var div = document.createElement("div");
div.setAttribute("class", "popup_container");
div.setAttribute("id", "popup");
div.innerHTML =
'<div class="popup" align="center">'+
'<img class="close" src="'+ this.img_close +'" alt="close" onclick="popup.fadeOut(\'popup\',0.1);" />'+
'<img src="'+ this.img +'" alt="popup"/>'+
'</div>';
window.onload = function(){
document.body.insertBefore(div,document.body.firstChild);
}
},
fadeIn:function(id, time) {
target = document.getElementById(id);
alpha = 0;
timer = (time*1000)/50;
var i = setInterval(
function() {
if (alpha >= 100)
clearInterval(i);
//popup.setAlpha(target, alpha);
alpha += 2;
}, timer);
},
fadeOut:function(id, time) {
target = document.getElementById(id);
alpha = 100;
timer = (time*1000)/50;
var i = setInterval(
function() {
if (alpha <= 0)
clearInterval(i);
popup.setAlpha(target, alpha);
alpha -= 2;
if(alpha==0){
target.parentNode.removeChild(target);
}
}, timer);
},
setAlpha:function(target, alpha) {
target.style.filter = "alpha(opacity="+ alpha +")";
target.style.opacity = alpha/100;
},
setup:function(img) {
popup.img = img;
popup.config();
popup.fadeIn('popup',0.1);
}
};
/*
$('body').append('<div id="popup_container">'+
'<div class="wrapper">'+
'<div class="popup_wrapper" align="center">'+
'<img id="close" src="popup/close.png" />'+
'<img src="userfiles/publicidade/7914f8574501f597f23c3f625a54134c.jpg" width="834" />'+
'</div>'+
'</div>'+
'</div>');
$('#popup_container').fadeIn();
$('#close').click(function(){
$('#popup_container').fadeOut();
});
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment