使用切换时在功能内执行单击

时间:2013-09-16 11:03:44

标签: jquery onclick

我有这个点击事件,第一次点击使图像和div更大,第二次点击我想为图像添加一个翻转效果,第三次点击使div和图像再次变小

//CLICK EVENT-------------------------------------------------------------------------------------------------------
                $(this).toggle(function()
                {
                    makes div and image bigger
                }, 
                function()  //2nd function for toggle
                {
                    var margin =$(".image1").width()/2;
                    var width=$(".image1").width();
                    var height=$(".image1").height();
                    $(".image2").stop().css({width:'0px',height:''+height+'px',marginLeft:''+margin+'px',opacity:'0.5'});
                    flip_image(this); 
                },
                function()  //3rd function for toggle
                {
                    Makes div and image smaller
                    function()
                    {
                        rotateByAmount(indexPointer, this);  //reset rotation
                    });
                });
//END CLICK EVENT-------------------------------------------------------------------------------------------------------

我试图修改功能flip_image所以当第二次点击发生时$(".image1").click(function()

会自动运行吗?这有可能吗?

function flip_image(thisImage) 
        {
                $(".image1").click(function(){
                    $(this).stop().animate({width:'0px',height:''+height+'px',marginLeft:''+margin+'px',opacity:'0.5'},{duration:500});
                    window.setTimeout(function() {
                    $(".image2").stop().animate({width:''+width+'px',height:''+height+'px',marginLeft:'0px',opacity:'1'},{duration:500});
                    },500);
                });

                $(".image2").click(function(){
                    $(this).stop().animate({width:'0px',height:''+height+'px',marginLeft:''+margin+'px',opacity:'0.5'},{duration:500});
                    window.setTimeout(function() {
                    $(".image1").stop().animate({width:''+width+'px',height:''+height+'px',marginLeft:'0px',opacity:'1'},{duration:500});
                    },500);
                });
        } 

0 个答案:

没有答案