jQuery .attr()与回调? [英] jquery .attr() with callback?

查看:81
本文介绍了jQuery .attr()与回调?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的电视机上,我使用jquery淡出图像,将其源更改为其他图像,然后再淡入.但是,有时在连接速度较慢的情况下,图像会在源完全更改之前淡入,因此旧图像将仍然会出现一小会儿,然后再出现新的声音.

On my set I use jquery to fadeout an image, change its source to something else, then fade back in. However, sometimes on slow connections, the image will fade back in before the source completely changes, so the old image will still appear for a brief second before the new one comes in.

有没有办法在attr上进行回调,以便仅在反映attr更改时才调用淡入?

Is there a way to have a callback on attr so fading back in is only called when the attr change is reflected?

$(".img").fadeTo("fast",0,function(){
    $(".img").attr({
        //some other stuff
        'src':url
    });
    $(".img").fadeTo("fast",1);
    //other stuff
});

我使用fadeTo而不是fadeIn(),因此图像尺寸得以保留.

I use fadeTo not fadeIn() so the image size is retained.

推荐答案

将事件处理程序绑定到 load事件,然后在处理程序中将其淡出.

Bind an event handler to the load event on the image, and fade it out in the handler.

这篇关于jQuery .attr()与回调?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆