jQuery:使用一个函数在不同方向上对两个图像进行动画处理

发布于 2024-10-29 18:40:53 字数 621 浏览 4 评论 0原文

我正在尝试使用单个函数来为两个不同的图像设置动画。我遇到的问题是其中一张图像需要为左侧属性设置动画,而另一张图像需要为右侧属性设置动画。我尝试了一些不同的事情,但据我所知:

    $(document).ready(function(){
        var puppy = $('.puppy'),
            woman = $('.woman-smiling');

        fadeImages(puppy, "left");
        fadeImages(woman, "right");
    });

    function fadeImages($image, $direction){
        $image.delay(500)
            .css({
                visibility: "visible",
                display: "none"
            }).animate({
                opacity: "show",
                $direction: "0px"
            }, 1750);
    }

延迟和衰落工作正常,但方向是混乱的。蒂亚!!!

I'm attempting to use a single function to animate two different images. The issue I'm having is that one of the images needs to animate the left attribute and the other needs to animate the right. I attempted a few different things, but this is as far as I got:

    $(document).ready(function(){
        var puppy = $('.puppy'),
            woman = $('.woman-smiling');

        fadeImages(puppy, "left");
        fadeImages(woman, "right");
    });

    function fadeImages($image, $direction){
        $image.delay(500)
            .css({
                visibility: "visible",
                display: "none"
            }).animate({
                opacity: "show",
                $direction: "0px"
            }, 1750);
    }

The delay and fading work fine, but the direction is what's messed up. TIA!!!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

心不设防 2024-11-05 18:40:53

我认为您不能像现在一样使用 $direction 。也许这会起作用:

function fadeImages($image, $direction){

    var properties = new Object();
    properties['opacity'] = "show";
    properties[$direction] = "0px";

    $image.delay(500)
        .css({
            visibility: "visible",
            display: "none"
        }).animate(properties, 1750);
}

I don't think you can use $direction like you are doing. Perhaps this would work:

function fadeImages($image, $direction){

    var properties = new Object();
    properties['opacity'] = "show";
    properties[$direction] = "0px";

    $image.delay(500)
        .css({
            visibility: "visible",
            display: "none"
        }).animate(properties, 1750);
}
撩人痒 2024-11-05 18:40:53

试试这个:

var config = { opacity: "show" };
config[$direction] = "0px;"

.animate(config, , 1750);

您所拥有的不起作用,因为在这种情况下它使用 $direction 作为 KEY,而不是用它替换变量的值。

Try this:

var config = { opacity: "show" };
config[$direction] = "0px;"

.animate(config, , 1750);

What you have is not working because it is using $direction as a KEY in that case, and not substituting it for your variable's value.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文