在jQuery 1.9删除.toggle(函数,函数)后使用的替代方法是什么?

Gle*_*shi 19 css jquery animation toggle

嗨,我正在尝试创建一些可以在每次点击时交替收缩和增长的东西,但我正在使用jQuery 1.9我的网站.该.toggle(function,function)功能已被删除jQuery 1.9,所以我不确定应该使用什么代替.

任何帮助都会很棒.

谢谢

jsfiddle(使用旧代码,jquery 1.8版本):http://jsfiddle.net/TNAC6/

新jsfiddle(jquery 1.9):http://jsfiddle.net/TNAC6/1/

这是我试图切换的代码.基本上我正在切换的是一个圆形div.

(function($){
    $.fn.createToggle = function(size) {
        var ele = $(this);
        var oldSize = ele.width();
        console.log("creating new toggle on element: " + ele + " old: " + oldSize + " new: " + size );
        console.log("its content is" + ele.children(".content"));
        var growfn = function() {
            $(this).stop().animate({
                'width': size+'px',
                'height': size+'px',
                'margin-left': '-'+(size/2)+'px',
                'margin-top': '-'+(size/2)+'px'
            }, 500);
            $(this).children(".content").toggle();
        };
        var shrinkfn = function() {
            $(this).stop().animate({
                'width': oldSize+'px',
                'height': oldSize+'px',
                'margin-left': '-'+(oldSize/2)+'px',
                'margin-top': '-'+(oldSize/2)+'px'
            }, 500);
            $(this).children(".content").toggle();
        };
        ele.click(function() {
//insert code to toggle stuff
        });
    };
})(jQuery);

$(".home").createToggle(500);
Run Code Online (Sandbox Code Playgroud)

和css:

.circleBase {
    -webkit-border-radius: 999px;
    -moz-border-radius: 999px;
    border-radius: 999px;
    behavior: url(PIE.htc);
}

.home {
    width: 200px;
    height: 200px;
    background: #FF5032;
    position: absolute;
    top: 300px;
    left: 300px;
    margin-left: -100px;
    margin-top: -100px;
}

.title {
    position: relative;
    padding-top: 10%;
    text-align: center;
    font-weight: bold;
    font-size: 24px;
}

.content {
    text-align: center;
    display: none;
}
Run Code Online (Sandbox Code Playgroud)

和HTML:

<div class="circleBase home">
    <p class="title">Glen Takahashi<p>
    <p class="content">THIS IS CONTENT<BR> THIS IS CONTENT<BR> THIS IS CONTENT<BR> THIS IS CONTENT<BR> THIS IS CONTENT</p>
</div>
Run Code Online (Sandbox Code Playgroud)

Exp*_*lls 6

有两种状态,你可以将当前的切换状态保持为布尔值(我使用过clickState).如果您想拥有多个状态,可以继续将状态计数加1,然后检查总计数的模数,以确定应根据状态触发哪个函数.

我更新了你的代码,因为ele它实际上是你想要使用的jQuery对象:

http://jsfiddle.net/TNAC6/2/