Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用jQuery切换div的高度_Jquery_Css - Fatal编程技术网

使用jQuery切换div的高度

使用jQuery切换div的高度,jquery,css,Jquery,Css,我正在尝试切换div的高度,该高度可能会有所不同。我想在用户单击按钮时将其切换为原始高度的10%,在单击“返回打开”时将其切换为100%。我还需要更改箭头的类别以反映当前的切换状态。我还没能把第二部分弄清楚。任何幼崽都将不胜感激 这是我到目前为止得到的 function togglePracticeDrills() { $("#drillHelpSlide").animate({height:"10%"}); $(".arrow").addClass("minimized");

我正在尝试切换div的高度,该高度可能会有所不同。我想在用户单击按钮时将其切换为原始高度的10%,在单击“返回打开”时将其切换为100%。我还需要更改箭头的类别以反映当前的切换状态。我还没能把第二部分弄清楚。任何幼崽都将不胜感激

这是我到目前为止得到的

function togglePracticeDrills() {
    $("#drillHelpSlide").animate({height:"10%"});
    $(".arrow").addClass("minimized");
};

谢谢

试试这样的方法:

function togglePracticeDrills() {
    constant originalHeight = ORIGINAL_HEIGHT_HERE;
    var tenPercentHeight = 0.1 * originalHeight;

    if ($(".arrow").hasClass("minimized")) {
        $("#drillHelpSlide").animate({height: originalHeight});
        $(".arrow").removeClass("minimized");
    } else {
        $("#drillHelpSlide").animate({height: tenPercentHeight});
        $(".arrow").addClass("minimized");
    }
}
var slideHeight = $("#drillHelpSlide").height();
$("#drillHelpSlide").animate({ height: (slideHeight / 10) });
var height = $('#drillHelpSlide').height() / orig_height;
var new_height = (height % 100) * 10;
$("#drillHelpSlide").animate({height: new_height + "%"});

试着这样做:

function togglePracticeDrills() {
    constant originalHeight = ORIGINAL_HEIGHT_HERE;
    var tenPercentHeight = 0.1 * originalHeight;

    if ($(".arrow").hasClass("minimized")) {
        $("#drillHelpSlide").animate({height: originalHeight});
        $(".arrow").removeClass("minimized");
    } else {
        $("#drillHelpSlide").animate({height: tenPercentHeight});
        $(".arrow").addClass("minimized");
    }
}
var slideHeight = $("#drillHelpSlide").height();
$("#drillHelpSlide").animate({ height: (slideHeight / 10) });
var height = $('#drillHelpSlide').height() / orig_height;
var new_height = (height % 100) * 10;
$("#drillHelpSlide").animate({height: new_height + "%"});

您可以尝试以下方法:

function togglePracticeDrills() {
    constant originalHeight = ORIGINAL_HEIGHT_HERE;
    var tenPercentHeight = 0.1 * originalHeight;

    if ($(".arrow").hasClass("minimized")) {
        $("#drillHelpSlide").animate({height: originalHeight});
        $(".arrow").removeClass("minimized");
    } else {
        $("#drillHelpSlide").animate({height: tenPercentHeight});
        $(".arrow").addClass("minimized");
    }
}
var slideHeight = $("#drillHelpSlide").height();
$("#drillHelpSlide").animate({ height: (slideHeight / 10) });
var height = $('#drillHelpSlide').height() / orig_height;
var new_height = (height % 100) * 10;
$("#drillHelpSlide").animate({height: new_height + "%"});
下面是一个工作示例:

<script type="text/javascript">
    $(function() {
        $("#collapse").click(function() {
            var elHeight = $("#test").height();
            $("#test").animate({ height: (elHeight / 10) });
        });
        $("#expand").click(function() {
            $("#test").animate({ height: "300px" });
        });
    });
</script>
<div id="test" style="height:300px;border:1px solid #ccc;">
    Hello world!
</div>
<input type="button" id="collapse" value="Collapse" />
<input type="button" id="expand" value="Expand" />

$(函数(){
$(“#折叠”)。单击(函数(){
var elHeight=$(“#测试”).height();
$(“#测试”).animate({height:(elHeight/10)});
});
$(“#展开”)。单击(函数(){
$(“#测试”).animate({height:“300px”});
});
});
你好,世界!

您可以尝试以下方法:

function togglePracticeDrills() {
    constant originalHeight = ORIGINAL_HEIGHT_HERE;
    var tenPercentHeight = 0.1 * originalHeight;

    if ($(".arrow").hasClass("minimized")) {
        $("#drillHelpSlide").animate({height: originalHeight});
        $(".arrow").removeClass("minimized");
    } else {
        $("#drillHelpSlide").animate({height: tenPercentHeight});
        $(".arrow").addClass("minimized");
    }
}
var slideHeight = $("#drillHelpSlide").height();
$("#drillHelpSlide").animate({ height: (slideHeight / 10) });
var height = $('#drillHelpSlide').height() / orig_height;
var new_height = (height % 100) * 10;
$("#drillHelpSlide").animate({height: new_height + "%"});
下面是一个工作示例:

<script type="text/javascript">
    $(function() {
        $("#collapse").click(function() {
            var elHeight = $("#test").height();
            $("#test").animate({ height: (elHeight / 10) });
        });
        $("#expand").click(function() {
            $("#test").animate({ height: "300px" });
        });
    });
</script>
<div id="test" style="height:300px;border:1px solid #ccc;">
    Hello world!
</div>
<input type="button" id="collapse" value="Collapse" />
<input type="button" id="expand" value="Expand" />

$(函数(){
$(“#折叠”)。单击(函数(){
var elHeight=$(“#测试”).height();
$(“#测试”).animate({height:(elHeight/10)});
});
$(“#展开”)。单击(函数(){
$(“#测试”).animate({height:“300px”});
});
});
你好,世界!

您可以这样做:

function togglePracticeDrills() {
    constant originalHeight = ORIGINAL_HEIGHT_HERE;
    var tenPercentHeight = 0.1 * originalHeight;

    if ($(".arrow").hasClass("minimized")) {
        $("#drillHelpSlide").animate({height: originalHeight});
        $(".arrow").removeClass("minimized");
    } else {
        $("#drillHelpSlide").animate({height: tenPercentHeight});
        $(".arrow").addClass("minimized");
    }
}
var slideHeight = $("#drillHelpSlide").height();
$("#drillHelpSlide").animate({ height: (slideHeight / 10) });
var height = $('#drillHelpSlide').height() / orig_height;
var new_height = (height % 100) * 10;
$("#drillHelpSlide").animate({height: new_height + "%"});

这是因为
100%100
=
1
;多重by
10
为您提供
10
<代码>10%100=
10
;乘以
10
得到
100

您可以这样做:

function togglePracticeDrills() {
    constant originalHeight = ORIGINAL_HEIGHT_HERE;
    var tenPercentHeight = 0.1 * originalHeight;

    if ($(".arrow").hasClass("minimized")) {
        $("#drillHelpSlide").animate({height: originalHeight});
        $(".arrow").removeClass("minimized");
    } else {
        $("#drillHelpSlide").animate({height: tenPercentHeight});
        $(".arrow").addClass("minimized");
    }
}
var slideHeight = $("#drillHelpSlide").height();
$("#drillHelpSlide").animate({ height: (slideHeight / 10) });
var height = $('#drillHelpSlide').height() / orig_height;
var new_height = (height % 100) * 10;
$("#drillHelpSlide").animate({height: new_height + "%"});
function togglePracticeDrills() {
  var origHeight = $('#drillHelpSlide').data('origHeight');

    if (origHeight) {
        $('#drillHelpSlide').removeData('origHeight');
        $('#drillHelpSlide').animate({height: origHeight});
    } else {
        origHeight = $('#drillHelpSlide').height();
        $('#drillHelpSlide').data('origHeight', origHeight);
        $('#drillHelpSlide').animate({height: origHeight * 0.1});
    }

    $(".arrow").addClass("minimized");
};
这是因为
100%100
=
1
;多重by
10
为您提供
10
<代码>10%100=
10
;乘以
10
得到
100

function togglePracticeDrills() {
  var origHeight = $('#drillHelpSlide').data('origHeight');

    if (origHeight) {
        $('#drillHelpSlide').removeData('origHeight');
        $('#drillHelpSlide').animate({height: origHeight});
    } else {
        origHeight = $('#drillHelpSlide').height();
        $('#drillHelpSlide').data('origHeight', origHeight);
        $('#drillHelpSlide').animate({height: origHeight * 0.1});
    }

    $(".arrow").addClass("minimized");
};


你可以试试这个。这里的
div
高度是
300px

function toggleDiv(){
var dv5 = document.getElementById('<%= Div5.ClientId %>');

if($(dv5).height()=="300")

        {
            $(dv5).css("height","30px");
        }
        else
        {
            $(dv5).css("height","300px");
        }
}
函数toggleDiv(){
var dv5=document.getElementById(“”);
如果($(dv5).height()=“300”)
{
$(dv5).css(“高度”,“30px”);
}
其他的
{
$(dv5).css(“高度”,“300px”);
}
}

您可以试试这个。这里的
div
高度是
300px

function toggleDiv(){
var dv5 = document.getElementById('<%= Div5.ClientId %>');

if($(dv5).height()=="300")

        {
            $(dv5).css("height","30px");
        }
        else
        {
            $(dv5).css("height","300px");
        }
}
函数toggleDiv(){
var dv5=document.getElementById(“”);
如果($(dv5).height()=“300”)
{
$(dv5).css(“高度”,“30px”);
}
其他的
{
$(dv5).css(“高度”,“300px”);
}
}

要将高度更改为
10%
,还是更改为当前高度的1/10?我要将高度更改为当前高度的10%。要将高度更改为
10%
,还是更改为当前高度的1/10?我要将高度更改为当前高度的10%。