javascript - JQuery - .animate <img>

标签 javascript jquery animation png image

早安先生。堆栈溢出。

是否可以在 2 个 img 之间制作动画?比如,将 img src 和 fade 更改为新的 img src?

HTML

<img class="classimg" src="images/example.png" />

我的伪 jquery/javascript 代码:

On Click
    Animate .classimg height 50 width 100 opacity 1, 600
    Animate .classimg height 200 width 450, 400
    Animate .classimg change img src to url(images/example_with_green.png), 700

感谢您的努力 - 祝您 12 月 1 日过得愉快!

最佳答案

正如罗伯特所说,你可以做的是:

<script type="text/javascript">

        $(function () {
            // find the div.fade elements and hook the hover event
            $('div.fade').hover(function() {
                // on hovering over find the element we want to fade *up*
                var fade = $('> div', this);

                // if the element is currently being animated (to fadeOut)...
                if (fade.is(':animated')) {
                    // ...stop the current animation, and fade it to 1 from current position
                    fade.stop().fadeTo(1000, 1);
                } else {
                    fade.fadeIn(1000);
                }
            }, function () {
                var fade = $('> div', this);
                if (fade.is(':animated')) {
                    fade.stop().fadeTo(1000, 0);
                } else {
                    fade.fadeOut(1000);
                }
            });
        });

    </script>

和 HTML:

    <div class="fade">
            <img src="logo.png" alt="Who we are" />
            <div>
                <img src="logoalt.png" alt="Who we are" />
    </div>
</div>

关于javascript - JQuery - .animate <img>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4322242/

相关文章:

php - jQuery $.ajax 和 php 删除文件

python - 如何获取利萨如曲线表中所有曲线的X和Y位置?

javascript - 引用 javascript 的母版页在 Visual Studio 中不起作用

javascript - 如何使用 jQuery 在菜单悬停时创建滑动动画?

javascript - 为什么 JavaScript 函数会因某些参数名称而失败?

javascript - 在 jQuery 中创建多个相同的元素

javascript - 如何将更改应用到 JavaScript 数组中的数据对象?

javascript - 在多个元素上调用 onClick 函数

animation - Xamarin 安卓 : Animated Splash Screen

android - 如何在 Android 中恢复和暂停 API 级别低于 19 的 ObjectAnimator?