Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/416.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用JQuery在Ajax之后平滑衰减_Javascript_Jquery_Fade - Fatal编程技术网

Javascript 使用JQuery在Ajax之后平滑衰减

Javascript 使用JQuery在Ajax之后平滑衰减,javascript,jquery,fade,Javascript,Jquery,Fade,我正在使用jqueryajax来更改网站中的页面。我的代码是: $('#'+target).fadeOut('slow', function(){ $('#' + target).children().remove().end().append('<div style="width:' + loadingImageWidth + 'px;height:' + loadingImageHeight + 'px;background-color:black;-moz-borde

我正在使用jqueryajax来更改网站中的页面。我的代码是:

$('#'+target).fadeOut('slow', function(){
        $('#' + target).children().remove().end().append('<div style="width:' + loadingImageWidth + 'px;height:' + loadingImageHeight + 'px;background-color:black;-moz-border-radius:15px;"></div>');
        $('#'+target).fadeIn('slow', function(){
            $.ajax({
                type: type,
                url: url,
                success: function(msg){
                    $('#'+target).fadeOut('slow', function(){
                        $('#'+target).html(msg);
                        $('#'+target).fadeIn('slow', function(){});
                    });
                }
            });
        });
    });
$('#'+target).fadeOut('slow',function(){
$('#'+target.children().remove().end().append('');
$('#'+target).fadeIn('slow',function()){
$.ajax({
类型:类型,
url:url,
成功:功能(msg){
$('#'+target).fadeOut('slow',function(){
$('#'+target).html(msg);
$('#'+target).fadeIn('slow',function(){});
});
}
});
});
});
我的问题是,当我使用淡入时,#target“div的宽度和高度发生变化,因此,我的页面的滚动变化,这真的很烦人,因为页面似乎在上下跳跃!我想知道如何使用JQuery来获得平滑效果。
thanx伙计们。

也许这能解决问题:


(但此错误自jQuery 1.3以来已被修复。)

在不查看标记和css的情况下很难进行诊断,但可行的方法是在设置动画时使目标的父对象保持其高度/宽度

可以通过在淡入淡出之前将父对象的尺寸设置为目标的高度,然后在淡入淡出完成时更新父对象的尺寸来完成此操作

开始之前,请执行以下操作:

$('#'+target).parent().height($('#'+target).height()).width($('#'+target).width());
然后可以在success块中调用相同的代码

另外,作为一个性能提示,字符串连接和dom搜索是昂贵的,最好缓存目标并在整个代码中使用它。例如:

var target = $('#'+target);
target.fadeOut('slow');

然后只执行一次连接和查找,并在整个代码中使用相同的引用。

我有JQuery v1.4.4版。但我不认为这能解决我的问题。Thanx伙计,我没有完全使用你的代码,但我写了一个代码,表达了你关于设置家长宽度和高度的想法。我在目标周围创建了一个新的div,并使用Ajax更改了它的宽度和高度。Thanx;)