another resizing issue with cycle plugin
Hello and thankyou in advance for any help, firstly a little about the problem I am having, I built the page around a single image at first, then decided to put a little slide show in the place, previously I had written a little script which adjusted the image size on initial load in the $(document).ready event. and also in the $(window).resize event the script looks like this .. and worked fine with an individual hard coded image.
- function adjustImage() {
- var imgWidth, imgHeight, ratio, parentWidth;
- $("img").each(function() {
- imgWidth = $(this).width();
- imgHeight = $(this).height();
- ratio = imgHeight / imgWidth;
- parentWidth = $(this).parent().width();
- $(this).height(parentWidth * ratio);
- $(this).width(parentWidth);
- });
- }
now this is the tricky part after adding the cycle plugin and working it around for my clients ease of use to load images from a JSON file I found that the script no longer adjusted the image size at all, I managed to fix that issue. here is the script which loads the images and activates the cycle plugin
- $(function() {
- $.getJSON("data/images.js", function(data) {
-
- $.each(data, function(key, val) {
- var items = [];
- for (var i=0; i < val.length; i++) {
- items.push('<img src="' + val[i].url + '" id="gallery' + i + '" alt="' + val[i].alt + '" title="' + val[i].title + '" class="ui-corner-all"></img>');
- }
- var h = items.join('');
- $(h).appendTo("#images");
- });
- })
-
- .fail(function( jqxhr, textStatus, error) {
- alert(error);
- })
- .done(function() {
- adjustImage();
- $("#images").cycle({
- fx: 'scrollVert',
- fit: 0,
- slideResize: 0
- });
- })
- });
notice the highlighted function which is called after the JSON call is done. this fixed some of the problems but everytime I resize the window, due to the nature of the layout the images would sometimes cover other content. I fixed this with another solution found elsewhere in my css file like this.
- #images {
- width: 100% !important;
- height: auto;
- }
this has solved the width resizing however the images still don't resize height.
now I am hoping there is a way that I can use my adjustImage function with cycle, even if it means destroying cycle and reinitialising it on window resize.