JQuery && google chrome

This script works fine in all browsers except Google Chrome.

$(document).ready(function(){
    $(".banners-anim img").each(function(){
        var hover_width = $(this).width();
        var hover_height = $(this).height();
        var unhover_width = (hover_width - 30);
        $(this).width(unhover_width);
        var unhover_height = $(this).height();
        $(this).closest("li").height(unhover_height);
        var offset = "-" + ((hover_height - unhover_height)/2) + "px";
        $(this).closest("span").css({'position':'absolute', 'left':'0', 'top':'25px', 'width':'100%'});
        $(this).hover(function(){
            $(this).animate({width: hover_width, marginTop: offset}, "fast")
        },function(){
            $(this).animate({width: unhover_width, marginTop: 0}, "fast")
        });
    });
});

Chrome does not recognize changed image attributes.

When changing, widthimg changes and height. Not even in Chrome ..

$(this).width(unhover_width);
var unhover_height = $(this).height();

unhover_heightgives 0.

Full code for this script (html enabled) - http://jsfiddle.net/BsqTe/

Please help fix this.

Thank.

+3
source share
2 answers

- jQuery ready, , . jQuery ready , , DOM , . - , , window load :

$(window).load(yourFunctionHere);
+7

, , onload. , IE , , - onload, . , , DoResize

var DoResize = function() { ... }
var img = $(".find .your img");
img.bind('load', DoResize);
img.bind('error', DoResize); // in case picture fails to load, still resize
if (img.get(0).complete) { DoResize(); }
0

Source: https://habr.com/ru/post/1750674/


All Articles