首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >动画GIF背景只显示一次

动画GIF背景只显示一次
EN

Stack Overflow用户
提问于 2013-10-15 23:25:45
回答 1查看 585关注 0票数 0

因此,在单击这些类偏振片图像时,我使用jQuery的<div class="poof"></div>来替换它们。我这样做的原因是为了显示一个动画gif动画,我使用js对该类进行样式设置。

然而,每次点击.polaroid**,(偏光体)图像的,** .poof div就取代了html,但是它的背景却没有显示出来。

你自己试试,给你

单击一个图像,它将被.poof div替换,但是动画的poof没有显示。

我非常感激有人能帮我弄清楚为什么会这样,以及如何让动画每次都能显示出来。

这是我的javascript:

代码语言:javascript
复制
   $(function(){
        var time=1;
        $('.polaroid').click(function(){
            $(this).replaceWith('<div class="poof"></div>');
            $('.poof').css('height', $(this).height()).css('width', $(this).width()).css('background', 'transparent url(poof.gif?t='+time+') center no-repeat');
            time++;
        });
});

以下是.poof的CSS:

代码语言:javascript
复制
.poof{
    height:32px;
    width:32px;
 }
EN

回答 1

Stack Overflow用户

发布于 2013-10-16 03:18:22

获取DOM中删除/替换的对象的高度和宽度。

改为:

代码语言:javascript
复制
var heights = 32;
var widths = 32;
$('.polaroid').click(function(){
    heights = $(this).height();
    widths = $(this).width();
    $('.poof').css('height', heights).css('width', widths).css('background', 'transparent url(http://i.imgur.com/FsVe2LC.gif?t='+time+') center no-repeat');
    time++;
    setTimeout(function(){
        $('.poof').remove();
    }, 1500);
});
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19392778

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档