最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - using jQuery slide toggle with min height - Stack Overflow

programmeradmin1浏览0评论

I am trying to use jQuerys slideToggle on a div that has a minimum height. this causes the animation to jump and not move smoothly. I have spent a while now looking for a solution but i am unable to get anything to work. I have made an example on jsfiddle and would appreciate if anyone could help me solve this issue.

my css for the div being toggled:

#selected-display{
    height:calc(100vh - 50px);
    display:none;
    min-height: 750px;
}

my javascript:

$(document).ready(function(){
    $(".toggle-display").click(function(){
        $("#selected-display").slideToggle("slow");

    });
});

/

I am trying to use jQuerys slideToggle on a div that has a minimum height. this causes the animation to jump and not move smoothly. I have spent a while now looking for a solution but i am unable to get anything to work. I have made an example on jsfiddle and would appreciate if anyone could help me solve this issue.

my css for the div being toggled:

#selected-display{
    height:calc(100vh - 50px);
    display:none;
    min-height: 750px;
}

my javascript:

$(document).ready(function(){
    $(".toggle-display").click(function(){
        $("#selected-display").slideToggle("slow");

    });
});

https://jsfiddle/4y3q27mh/

Share Improve this question asked Mar 6, 2015 at 0:02 Neil AldredNeil Aldred 1073 silver badges9 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5

https://jsfiddle/rqkt58L1/

You could just disable min-height during the animation, and then turn it back on when the animation is over:

$(document).ready(function () {
  $(".toggle-display").click(function () {
    var minHeight = $("#selected-display").css('min-height');
    $("#selected-display").css('min-height',0).slideToggle("slow", function() {
        $(this).css('min-height', minHeight);
    });
  });
});

Answer by dave works, but there is no animation to min-height. it just "appears"

I have solve it with javascript without using min-height:

function toggle(item) {
    if (item.height() < 350) {
        item.css('height', 350);
    }
    item.slideToggle();
}

发布评论

评论列表(0)

  1. 暂无评论