I am trying to develop code in which jquery accepts images and resizes them to fit the parent div, with the ability to click on the image to view it in full size with fancybox. I try to make all the images using the "expand" class and do not expect that you will have more than the image with this class on the page.
Below I guess. The image is very easy to change, and I can click on the image to raise the fancybox, but it has a size that has not been resized, not the original. I have fwidth and fheight as vars for the original measurements, but specifying them does not work, since its built-in. So, I need to use an iframe, which I found out, and tried a .wrap link around it and specify the link as an iframe with the specified dimensions, capturing .attr ("src") for the link. But no matter what I do, it goes to 404 page in fancybox. Below I have, I'm not sure how to proceed further, or am I thinking about this problem wrong?
if($('img.expand').length){ var parentClass = $('img.expand').parent().attr("class"); var fwidth = $('img.expand').attr("width"); var fheight = $('img.expand').attr("height"); if($('img.expand').parents().is('.grid_10')){ $('img.expand').each(function() { var maxwidth = 590; var obj = $('img.expand'); var width = obj.width(); var height = obj.height(); if (width > maxwidth) { //Set variables for manipulation var ratio = (height / width ); var new_width = maxwidth; var new_height = (new_width * ratio); //Shrink the image and add link to full-sized image obj.height(new_height).width(new_width); } }); } $('img.expand').fancybox({ 'transitionIn' : 'fade', 'transitionOut' : 'fade', 'speedIn' : 600, 'speedOut' : 200, 'overlayShow' : false, 'titlePosition' : 'inside' }); }
source share