JQuery Slider 不流畅,写错了?

发布于 2024-12-01 04:00:21 字数 3742 浏览 2 评论 0原文

因此,在我不懈努力以更好地使用 JQuery 的过程中,我构建了这个水平滑块。这个想法是,当悬停时,div 标签会展开,并且它的文本不透明度变得可见。其他 div 标签的标题会淡出。

看起来效果不错,但动画似乎有点不稳定。我将整个背景设为绿色,这样您就可以在右侧看到它的宽度如何不时变化。

有没有更好

的方法这还是我只是让动画过度紧张?

   $(function() {

$("#one").hover(

        function() {
        $("#two, #three, #four, #five").stop().animate({width: 50,  }, 1000);
        $("#titletwo, #titlethree, #titlefour, #titlefive").stop().animate({opacity:0.0}, 500);
        $("#blockone").stop().animate({opacity:1.0}, 1500);
        $("#one").stop().animate({width:700, }, 1000);

                },

        function() {
        $("#two, #three, #four, #five").stop().animate({width: 180, opacity:1.0 }, 1000);
        $("#titletwo, #titlethree, #titlefour, #titlefive").stop().animate({opacity:1.0}, 1000);
        $("#blockone").stop().animate({opacity:0.0}, 500);
        $("#one").stop().animate({width: 180 }, 1000);
                }

);
 });

$(function() {

$("#two").hover(

        function() {
        $("#one, #three, #four, #five").stop().animate({width: 50 }, 1000);
        $("#titleone, #titlethree, #titlefour, #titlefive").stop().animate({opacity:0.0}, 500);
        $("#blocktwo").stop().animate({opacity:1.0}, 1500);
        $("#two").stop().animate({width:700 }, 1000);

                },

        function() {
        $("#one, #three, #four, #five").stop().animate({width: 180 }, 1000);
        $("#titleone, #titlethree, #titlefour, #titlefive").stop().animate({opacity:1.0}, 1000);
        $("#blocktwo").stop().animate({opacity:0.0}, 500);
        $("#two").stop().animate({width: 180 }, 1000);
                }

);
 });

$(function() {

$("#three").hover(

        function() {
        $("#two, #one, #four, #five").stop().animate({width: 50 }, 1000);
        $("#titletwo, #titleone, #titlefour, #titlefive").stop().animate({opacity:0.0}, 500);
        $("#blockthree").stop().animate({opacity:1.0}, 1500);
        $("#three").stop().animate({width:700 }, 1000);

                },

        function() {
        $("#two, #one, #four, #five").stop().animate({width: 180 }, 1000);
        $("#titletwo, #titleone, #titlefour, #titlefive").stop().animate({opacity:1.0}, 1000);
        $("#blockthree").stop().animate({opacity:0.0}, 500);
        $("#three").stop().animate({width: 180 }, 1000);
                }

);
 });

$(function() {

$("#four").hover(

        function() {
        $("#two, #three, #one, #five").stop().animate({width: 50 }, 1000);
        $("#titletwo, #titlethree, #titleone, #titlefive").stop().animate({opacity:0.0}, 500);
        $("#blockfour").stop().animate({opacity:1.0}, 1500);
        $("#four").stop().animate({width:700 }, 1000);

                },

        function() {
        $("#two, #three, #one, #five").stop().animate({width: 180 }, 1000);
        $("#titletwo, #titlethree, #titleone, #titlefive").stop().animate({opacity:1.0}, 1000);
        $("#blockfour").stop().animate({opacity:0.0}, 500);
        $("#four").stop().animate({width: 180 }, 1000);
                }

);
 });

$(function() {

$("#five").hover(

        function() {
        $("#two, #three, #four, #one").stop().animate({width: 50 }, 1000);
        $("#titletwo, #titlethree, #titlefour, #titleone").stop().animate({opacity:0.0}, 500);
        $("#blockfive").stop().animate({opacity:1.0}, 1500);
        $("#five").stop().animate({width:700 }, 1000);

                },

        function() {
        $("#two, #three, #four, #one").stop().animate({width: 180 }, 1000);
        $("#titletwo, #titlethree, #titlefour, #titleone").stop().animate({opacity:1.0}, 1000);
        $("#blockfive").stop().animate({opacity:0.0}, 500);
        $("#five").stop().animate({width: 180 }, 1000);
                }

);
 });

So in my tireless effort to get better with JQuery, I built this horizontal slider. The idea is, when hovered, a div tag expands and it's text opacity becomes visible. The other div tags' titles are meant to fade out.

It seems to work ok, but the animation seems a little choppy. I made the entire background green so you can see on the right how it varies in width from time to time.

http://s354510196.onlinehome.us/TEMPDUMP/JQuerySlider/

Is there a better method for this or am I simply straining the animation too much?

   $(function() {

$("#one").hover(

        function() {
        $("#two, #three, #four, #five").stop().animate({width: 50,  }, 1000);
        $("#titletwo, #titlethree, #titlefour, #titlefive").stop().animate({opacity:0.0}, 500);
        $("#blockone").stop().animate({opacity:1.0}, 1500);
        $("#one").stop().animate({width:700, }, 1000);

                },

        function() {
        $("#two, #three, #four, #five").stop().animate({width: 180, opacity:1.0 }, 1000);
        $("#titletwo, #titlethree, #titlefour, #titlefive").stop().animate({opacity:1.0}, 1000);
        $("#blockone").stop().animate({opacity:0.0}, 500);
        $("#one").stop().animate({width: 180 }, 1000);
                }

);
 });

$(function() {

$("#two").hover(

        function() {
        $("#one, #three, #four, #five").stop().animate({width: 50 }, 1000);
        $("#titleone, #titlethree, #titlefour, #titlefive").stop().animate({opacity:0.0}, 500);
        $("#blocktwo").stop().animate({opacity:1.0}, 1500);
        $("#two").stop().animate({width:700 }, 1000);

                },

        function() {
        $("#one, #three, #four, #five").stop().animate({width: 180 }, 1000);
        $("#titleone, #titlethree, #titlefour, #titlefive").stop().animate({opacity:1.0}, 1000);
        $("#blocktwo").stop().animate({opacity:0.0}, 500);
        $("#two").stop().animate({width: 180 }, 1000);
                }

);
 });

$(function() {

$("#three").hover(

        function() {
        $("#two, #one, #four, #five").stop().animate({width: 50 }, 1000);
        $("#titletwo, #titleone, #titlefour, #titlefive").stop().animate({opacity:0.0}, 500);
        $("#blockthree").stop().animate({opacity:1.0}, 1500);
        $("#three").stop().animate({width:700 }, 1000);

                },

        function() {
        $("#two, #one, #four, #five").stop().animate({width: 180 }, 1000);
        $("#titletwo, #titleone, #titlefour, #titlefive").stop().animate({opacity:1.0}, 1000);
        $("#blockthree").stop().animate({opacity:0.0}, 500);
        $("#three").stop().animate({width: 180 }, 1000);
                }

);
 });

$(function() {

$("#four").hover(

        function() {
        $("#two, #three, #one, #five").stop().animate({width: 50 }, 1000);
        $("#titletwo, #titlethree, #titleone, #titlefive").stop().animate({opacity:0.0}, 500);
        $("#blockfour").stop().animate({opacity:1.0}, 1500);
        $("#four").stop().animate({width:700 }, 1000);

                },

        function() {
        $("#two, #three, #one, #five").stop().animate({width: 180 }, 1000);
        $("#titletwo, #titlethree, #titleone, #titlefive").stop().animate({opacity:1.0}, 1000);
        $("#blockfour").stop().animate({opacity:0.0}, 500);
        $("#four").stop().animate({width: 180 }, 1000);
                }

);
 });

$(function() {

$("#five").hover(

        function() {
        $("#two, #three, #four, #one").stop().animate({width: 50 }, 1000);
        $("#titletwo, #titlethree, #titlefour, #titleone").stop().animate({opacity:0.0}, 500);
        $("#blockfive").stop().animate({opacity:1.0}, 1500);
        $("#five").stop().animate({width:700 }, 1000);

                },

        function() {
        $("#two, #three, #four, #one").stop().animate({width: 180 }, 1000);
        $("#titletwo, #titlethree, #titlefour, #titleone").stop().animate({opacity:1.0}, 1000);
        $("#blockfive").stop().animate({opacity:0.0}, 500);
        $("#five").stop().animate({width: 180 }, 1000);
                }

);
 });

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

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

发布评论

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

评论(1

奢华的一滴泪 2024-12-08 04:00:21

我猜四个并行的停止/动画没有帮助。

顺便说一下,你可以像这样重写整个块,但这不会改变性能

$('.slide').hover( 

    function () {
        $this = $(this);
        $siblings = $this.siblings();

        $siblings.stop().animate({width: 50,  }, 1000);
        $('.fronttitle', $siblings).stop().animate({opacity:0.0}, 500);
        $('.backblock', $this).stop().animate({opacity:1.0}, 1500);
        $this.stop().animate({width:700, }, 1000);

    },
    function () {
        $this = $(this);
        $siblings = $this.siblings();

        $siblings.stop().stop().animate({width: 180, opacity:1.0 }, 1000);
        $('.fronttitle', $siblings).stop().animate({opacity:1.0}, 1000);
        $('.backblock', $this).stop().animate({opacity:0.0}, 500);
        $this.stop().animate({width: 180 }, 1000);
    }   
);

the four parrallel stop/animate do not help I guess.

by the way you can rewrite the full block like this, but it won't change performance

$('.slide').hover( 

    function () {
        $this = $(this);
        $siblings = $this.siblings();

        $siblings.stop().animate({width: 50,  }, 1000);
        $('.fronttitle', $siblings).stop().animate({opacity:0.0}, 500);
        $('.backblock', $this).stop().animate({opacity:1.0}, 1500);
        $this.stop().animate({width:700, }, 1000);

    },
    function () {
        $this = $(this);
        $siblings = $this.siblings();

        $siblings.stop().stop().animate({width: 180, opacity:1.0 }, 1000);
        $('.fronttitle', $siblings).stop().animate({opacity:1.0}, 1000);
        $('.backblock', $this).stop().animate({opacity:0.0}, 500);
        $this.stop().animate({width: 180 }, 1000);
    }   
);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文