开发者

Galleria Javascript Gallery in IE7 & IE8

开发者 https://www.devze.com 2022-12-19 06:25 出处:网络
I have implemented the Galleria & SmoothDivScroll plug-ins together but in IE7 & IE8 the image gets distorted [ratio is not kep开发者_运维技巧t in scaling] slightly when its orientation is por

I have implemented the Galleria & SmoothDivScroll plug-ins together but in IE7 & IE8 the image gets distorted [ratio is not kep开发者_运维技巧t in scaling] slightly when its orientation is portrait (i.e. when the image gets loaded into #main_image, the image container).

In Safari and Firefox, everything is fine. Does anyone else encounter this problem? How did you fix this?


I found that it was some CSS giving me problems. IE7 & IE8 apparently does not know how to handle scaling while keeping the ratio the same. I gave the image width & height properties, and that seemed to fix it.


I have just taken apart my whole page and put it back together to find that it was one comma in my options

// Initialize Galleria
$('#galleria').galleria({
width:764,
transition: 'fade',
autoplay: 8000,
idleTime: 1000000, <-----THIS COMMA HERE (remove this)
});

As soon as I removed this, the whole thing worked on IE7. I don't know if this is of any help to anybody now and it is also probably something quite obvious to many.


The key I've found to fix many problems is to move Galleria.loadTheme() outside of (document).ready().

Try that first, and mess with other things if that doesn't work.


i had a similar problem too, i think smoothdivscroll doesn't work well with ie, because, in my problem, i have used smoothdivscroll and jflow, it worked perfectly on firefox, chrome, safari, opera, etc but on ie 7 and 8, everything was running a little crazy. hours and days trying to solve the problem, i tried to remove and put things one by one, after removing the scroll div, everything worked like a charm on ie :)

The site that i had that problem: www.jardinsbelohorizonte.com

José Moreira


I found a more complete solution that will force a width property that is scaled correctly:

Firstly you need to add an id to the large image, to do this alter the following line of code in the onPageLoad function in the jquery.galleria.js file:

var _img   = $(new Image()).attr('src',_src).addClass('replaced');

add to it so that it now looks like the following:

var _img   = $(new Image()).attr('src',_src).attr('id','mainImg').addClass('replaced');

This now adds an id to the image so it can be targeted.

Next, in your index file (or where ever you have placed the code that initiates the gallery) you now alter the code as below:

// fade in the image & caption
if(! ($.browser.mozilla && navigator.appVersion.indexOf("Win")!=-1) ) { // FF/Win fades large images terribly slow
     image.css('display','none').fadeIn(1000);
}
var newHeight = 420;
var mainImage = document.getElementById('mainImg');
var imgInitHeight = mainImage.height;
var imgInitWidth = mainImage.width;
var imgScaleRatio = newHeight/imgInitHeight;
var newWidth = Math.ceil(imgInitWidth*imgScaleRatio);
image.css('height', newHeight);
image.css('width', newWidth);
caption.css('display','none').fadeIn(1000);

The variable newHeight is the height you would like the large image to be displayed at. Next you need to target the image in order to obtain its height and width BEFORE it is resized, these values are stored in imgInitHeight and imgInitWidth respectively. Now, seeing as you know the newHeight and imgInitHeight values it is possible to calculate the ratio by which the image must be scaled for it to reach its new dimensions, this is stored in the imgScaleRatio property.

Once the ratio is determined, you can now calculate the newWidth of the image and be confident that this is scaled correctly. Once this is done simply apply the css values to the image and youre done! Hope this helps someone.

Jon Tivy-Jones


I got this fix for getting jQuery Gallery working on IE8 + Windows Vista.

  1. Get the galleria code outside from:

 

jQuery(document).ready(function(){    
  //your code here    
});
  1. Load Gallery in this way:

var interval;

Galleria.loadTheme(’/js/galleria.classic.js’);
interval = setInterval(’loadMyGalleria()’,1000);
function loadMyGalleria() {
  if ($(’#galleria > div’).size() == 0) {
    $(’#galleria’).galleria({
      image_crop: true,
      transition: ‘fade’,
      transition_speed: 1000,
      data_config: function(img) {
      return {
        description: $(img).next(’p').html() };
      }
    });
    clearInterval(interval);
  }
0

精彩评论

暂无评论...
验证码 换一张
取 消