2

我试图在点击时淡出块,然后更改块位置,然后淡入。但它不起作用。这是代码:

$("#info-panel").fadeOut("fast");

$("#info-panel").css({
    top: (new pos),
    left: (new pos)
});

$("#info-panel").fadeIn("fast");

CSS:

#info-panel {
    display: none;
    position: absolute;
    background-color: #333;
    border: 1px solid #999;
    padding: 15px;
    max-width: 300px;
    -webkit-border-radius: 10px;
    -moz-border-radius: 10px;
    border-radius: 10px;
    -webkit-box-shadow: inset 0px 0px 10px #000;
    -moz-box-shadow: inset 0px 0px 10px #000;
    box-shadow: inset 0px 0px 10px #000;
    border: 3px solid #666666;
    z-index: 5;
}
4

3 回答 3

3

尝试这样的事情:

$("#info-panel").fadeOut("fast", function() {
    $(this).css("color", "red"); //Use your CSS here, I did this as an example.
}).fadeIn("fast");

演示:http: //jsfiddle.net/tymeJV/RPxrS/

于 2013-05-13T16:08:29.970 回答
1

您需要在这里使用回调函数:

$("#info-panel").fadeOut("fast", function () {
    $(this).animate({
        top: (new pos),
        left: (new pos)
    }, "fast", function () {
        // Animation complete.
        $(this).fadeIn("fast");
    });
});

在这里演示

于 2013-05-13T16:21:26.057 回答
0

检查您的元素是如何通过 css 定位的,请参阅:https ://developer.mozilla.org/en-US/docs/Web/CSS/position?redirectlocale=en-US&redirectslug=CSS%2Fposition

在这个片段中对我来说很好:

#info-panel {
    position:absolute
}

$("#moveme").click(function () {    
    $("#info-panel").fadeOut("fast");

    $("#info-panel").css({
        top: '80px',
        left: '70px'
    });
    $("#info-panel").fadeIn("fast");
});

小提琴:http: //jsfiddle.net/IrvinDominin/GHXg3/

于 2013-05-13T16:13:00.220 回答