如果在页面中使用两次,则无法重新加载相同的gif图像

时间:2017-01-11 14:26:02

标签: javascript html css gif

我在页面中使用两次相同的gif图像。两个图像最初都将被隐藏。基于某些标准,我正在显示那些gif图像(当点击特定目标时,将一次显示一个gif图像)。我无法重新加载gif图像。请参阅附带的plunker

1)https://plnkr.co/edit/vqZCHkyq7zCRCLpe9osF?p=preview

    <script>
    var img1 = document.getElementById("img1");
    var img2 = document.getElementById("img2");

    function toggle1() {
        if (document.getElementById('gif-1').style.display == "none") {
            document.getElementById('gif-1').src = '';
            document.getElementById('gif-1').src = 'http://insightgraphicdesign.net/wp-content/uploads/2014/07/coke-responsive-logo.gif';
            document.getElementById('gif-1').style.display = "block";
        } else
            document.getElementById('gif-1').style.display = "none";
    }

    function toggle2() {
        if (document.getElementById('gif-2').style.display == "none") {
            document.getElementById('gif-2').src = '';
            document.getElementById('gif-2').src = 'http://insightgraphicdesign.net/wp-content/uploads/2014/07/coke-responsive-logo.gif';
            document.getElementById('gif-2').style.display = "block";
        } else
            document.getElementById('gif-2').style.display = "none";
    }
</script>

但是如果我使用一个gif图像它正常工作,看到这个plunker(有时它不工作可能是由于安全性的plunker阻止。更好把它放在一个HTML和检查)

2)https://plnkr.co/edit/74huqUZmkoc6T6BdNOlz?p=preview

    <script>
    var img1 = document.getElementById("img1");

    function toggle1() {
        if (document.getElementById('gif-1').style.display == "none") {
            document.getElementById('gif-1').src = '';
            document.getElementById('gif-1').src = 'http://insightgraphicdesign.net/wp-content/uploads/2014/07/coke-responsive-logo.gif';
            document.getElementById('gif-1').style.display = "block";
        } else
            document.getElementById('gif-1').style.display = "none";
    }

</script>

任何人都可以帮我让plunker 1工作吗? (每当我点击两个按钮时,两个gif图像都会重新加载。)

谢谢, HariKrishnan P

0 个答案:

没有答案