【问题标题】:can jquery toggle the original css(style.css) value and the new value(set in the .animate{})?jquery可以切换原始css(style.css)值和新值(在.animate{}中设置)吗?
【发布时间】:2010-02-07 09:58:34
【问题描述】:

erm...jquery 可以切换原始 css(style.css) 值和新值(在 .animation{} 中设置)吗?

$(function() {
    $('a.maximize').click(function() {
        $($(this).attr('href')).animate({
        position: "absolute",
        top: 0,
        left: 0,
        height: '99.5%',
        width: '99.5%',
        opacity: 1,
  },1000)
});
});

这是我现在拥有的 jquery 代码,但是如何将 a href 目标切换为新值(上面的代码)

或者设置点击后的.animate{}变化,再次点击后又变回原来的.animate{}。

示例:同一个按钮, 但是第一次点击,改成宽高100%,

但是第二次点击同一个按钮,把它们改回宽高50%

第三次改为宽高100%,以此类推..

【问题讨论】:

  • $($(this).attr('href')) - 它是什么? o_O

标签: javascript jquery


【解决方案1】:

是的,您可以通过 .toggle() 做到这一点

像这样:

$('selector').toggle(func1,func2/*,func3, so on..*/)

然后定义你的函数

function func1(){
   // do something...
}
function func2(){
   // do something...
}

toggle 中的函数从第一个函数执行到最后一个函数,然后返回开始。

或者你也可以

$('selector').toggle(function(){...},function(){...}/*,function(){...}, so on..*/)

向下滚动到演示底部here 看看我的意思。

我还做了一个快速演示here

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-06-06
    • 1970-01-01
    • 2011-05-13
    • 1970-01-01
    • 1970-01-01
    • 2013-12-26
    • 2023-03-05
    相关资源
    最近更新 更多