javascript - 仅在为其 margin-left 设置动画时更改图像 Src

标签 javascript jquery html css animation

为了浏览器游戏的目的,我只想在图像正在动画时将图像 src 更改为动画 gif。

$(the_image_selector).animate({marginLeft: amount}, time);

我该怎么做?

我的想法是在调用animate之前把图片转成gif,然后用animate的回调把图片改回来。会成功吗?

最佳答案

是的,我确实认为你的策略会奏效,例如

var image = $(the_image_selector);

image.attr('src', 'url to show while animated');

image.animate({marginLeft: amount}, time, function(){
    image.attr('src', 'normal url');
});

关于javascript - 仅在为其 margin-left 设置动画时更改图像 Src,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23129374/

相关文章:

javascript - 通过文本值获取属性值

javascript - 不能添加相同的js

javascript - 使用 jQuery 在 3 秒内使输入文本不可编辑,然后再次可编辑

jquery - CSS 如何将菜单/导航的高度扩展到页脚?

用于游戏 UI 的 Javascript 框架

html - 如何将 Bootstrap 导航栏移至页面下方

javascript - [codeplayer]当 iframe 内容是使用 javascript 从文本区域动态加载时,如何在 iframe 中查找元素

javascript - 如何基于 JSON 输出创建 Bootstrap 面板

jquery - JScrollpane 不显示

html - 如何修复红色/蓝色背景(Windows、Firefox、Chrome 等)上的模糊/像素化字体渲染?