I have this popup that when u click on an image a popup display and has a nice effect of same picture background underneath, i want same effect on the clickable image that triggers the popup and i cant make it work, can anyone pls help me?
popup = {
init: function(){
$('figure').click(function(){
popup.open($(this));
});
$(document).on('click', '.popup img', function(){
return false;
}).on('click', '.popup', function(){
popup.close();
})
},
open: function($figure) {
$('.gallery').addClass('pop');
$popup = $('<div class="popup" />').appendTo($('body'));
$fig = $figure.clone().appendTo($('.popup'));
$bg = $('<div class="bg" />').appendTo($('.popup'));
$close = $('<div class="close"><svg><use xlink:href="#close"></use></svg></div>').appendTo($fig);
$shadow = $('<div class="shadow" />').appendTo($fig);
src = $('img', $fig).attr('src');
$shadow.css({backgroundImage: 'url(' + src + ')'});
$bg.css({backgroundImage: 'url(' + src + ')'});
setTimeout(function(){
$('.popup').addClass('pop');
}, 10);
},
close: function(){
$('.gallery, .popup').removeClass('pop');
setTimeout(function(){
$('.popup').remove()
}, 100);
}
}
popup.init()
https://codepen.io/adycobra/pen/XWwdrxr?editors=1011 here is the pen where im struggling and you can see all the code
New contributor
Lica Adrian is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.