javascript - Lightbox like a popup -
this code lightbox, it's necessary click show content, , need appearing without click. automatic. kind pop up.
$(document).ready(function() { $('.lightbox').click(function() { $('.background, .box').animate({ 'opacity': '.60' }, 500, 'linear'); $('.box').animate({ 'opacity': '1.00' }, 500, 'linear'); $('.background, .box').css('display', 'block'); }); $('.close').click(function() { $('.background, .box').animate({ 'opacity': '0' }, 500, 'linear', function() { $('.background, .box').css('display', 'none'); });; }); $('.background').click(function() { $('.background, .box').animate({ 'opacity': '0' }, 500, 'linear', function() { $('.background, .box').css('display', 'none'); });; }); });
how's this? move code functions , run open popup function on document ready:
$(document).ready(function() { $('.lightbox').click(function() { openpopup(); }); $('.close').click(function() { closepopup(); }); $('.background').click(function() { closepopup(); }); openpopup(); }); function openpopup() { $('.background, .box').animate({ 'opacity': '.60' }, 500, 'linear'); $('.box').animate({ 'opacity': '1.00' }, 500, 'linear'); $('.background, .box').css('display', 'block'); } function closepopup() { $('.background, .box').animate({ 'opacity': '0' }, 500, 'linear', function() { $('.background, .box').css('display', 'none'); }); }
Comments
Post a Comment