在jQuery中动画从右到左的问题

时间:2015-01-26 10:12:37

标签: jquery animation

正如你在这里看到的那样:http://jsfiddle.net/poxgawf4/,它的工作方向是左右。我想完全相反;从右 - 左。 我怎样才能做到这一点 ? THX

$(".inno-bg").mouseenter(function(){
    $(this).find("h2").stop(true, true).animate({
        'marginTop': "-=60px"
    }, 200);
    $(this).css('background-image', 'none');
    $(this).css("background-color", "#1A6397");
    $(this).stop(true, false).animate({ width: "320px" });
    $(this).find("p").fadeIn( 1000 );
});

$(".inno-bg").mouseleave(function(){
    $(this).find("h2").stop(true, true).animate({
        'marginTop' : "+=60px"
    }, 200);
    imageUrl = "http://www.esa.int/var/esa/storage/images/esa_multimedia/images/2014/02/gaia_calibration_image/14263603-2-eng-GB/Gaia_calibration_image_node_full_image_2.jpg";
    $(this).css('background-image', 'url(' + imageUrl + ')');
    $(this).stop(true, false).animate({ width: "160px" });
    $(this).find("p").hide();
});

1 个答案:

答案 0 :(得分:0)

在从右到左动画任何内容时,您需要将其绝对放置在其容器中。这是因为默认情况下,元素键入左上角,需要更改为右上角。试试这个,请注意我只包含了我在这里更改/添加的属性:

.row {
    position: relative;
}
.inno-bg {
    position: absolute;
    top: 0;
    right: 0;
}

Example fiddle