简体   繁体   English

jQuery .animate滑动面板

[英]jQuery .animate Sliding Panels

I'm trying to create a grid that uses the following code to randomly apply an active "highlight" class to one of the child li elements 我正在尝试创建一个网格,该网格使用以下代码将活动的“突出显示”类随机应用于子li元素之一

 //add class "highlight" to random panel

var elements = $('ul#sliding_panels li');
$ (elements.get (
  Math.round (elements.length*Math.random ()-0.5)
)).addClass ('highlight');

Basically, the li element with the .highlight class will be 2x the size of the other panels. 基本上,具有.highlight类的li元素将是其他面板的2倍。

The tricky part is that I'm looking to remove this .highlight class and attach it to a new li element when it is highlighted. 棘手的部分是,我希望删除此.highlight类并将其突出显示时附加到新的li元素上。

I thought this code would do the trick but it's not returning anything when I hover .highlight (or doing anything else for that matter!) 我以为这段代码可以解决问题,但是当我将.highlight悬停时,它什么也不返回(或者做任何其他事情!)

EDIT: I've added the code to jsfiddle.net for people to see it live: http://jsfiddle.net/dxzqv/2/ 编辑:我已将代码添加到jsfiddle.net,以便人们实时查看它: http : //jsfiddle.net/dxzqv/2/

    <script>

//add class "highlight" to random panel
        $(document).ready(function(){         

            var elements = $('ul#sliding_grid li');
            $ (elements.get (
              Math.round (elements.length*Math.random ()-0.5)
            )).addClass ('highlight');        

//animation on hover            

            $('#sliding_grid li').hover(function() {
              $(this).addClass('highlight');
            }, function() {
              $(this).removeClass('highlight');
            });

            $(".highlight").hover(
                function(){$(this).animate({width: 400px, height:400px}, 1000);},        
                function(){$(this).animate({width: 200px, height:200px}, 1000);}
            );        

        });

    </script>

http://jsfiddle.net/dxzqv/3/ http://jsfiddle.net/dxzqv/3/

How's that? 怎么样?

Not sure if that is the effect you were going for, stuff is happening. 不知道这是否是您想要的效果,事情正在发生。

Going to fork and tweak some more. 要分叉并进行更多调整。

//add class "highlight" to random panel
        $(document).ready(function(){         

            var elements = $('ul#sliding_grid li');
            $ (elements.get (
              Math.round (elements.length*Math.random ()-0.5)
            )).addClass ('highlight');        

//animation on hover            

            $('#sliding_grid li').hover(function() {
              $(this).addClass('highlight');
            }, function() {
              //$(this).removeClass('highlight');
            });

            $(".highlight").live("hover", function(){
                $(this).animate({"width": "400px", "height":"400px"}, 1000);       

            });   

            $(".highlight").live("mouseout", function(){
                $(this).animate({"width": "200px", "height":"200px"}, 1000, function(){
                 $(this).removeClass('highlight');   
                });        

            });        

        });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM