$(document).ready(function(){ $("img[name='show_img']").click(function() { var imgsrc = $(this).attr('src'); $('#img_alert .img_content img').attr('src', imgsrc); $('#img_alert').show(); var height = $('#img_alert .img_content').height(); $('#img_alert .img_content').css({ 'margin-top': -(height / 2), 'opacity': '1' }) }) $('#img_alert .img_content .closed').click(function(){ $(this).parents('.img_content').css({ 'opacity': '0' }) $('#img_alert').hide(); }) }); /* $("img[name='show_img']").click(function() { var imgsrc = $(this).attr('src'); $('#img_alert .img_content img').attr('src', imgsrc); $('#img_alert').show(); var height = $('#img_alert .img_content').height(); if(height==0){ height = -250; }else { height = -(height / 2); } $('#img_alert .img_content').css({ 'margin-top': height, 'opacity': '1' }) }) $('#img_alert .img_content .closed').click(function(){ $(this).parents('.img_content').css({ 'opacity': '0' }) $('#img_alert').hide(); })*/