且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

javascript,当div div被隐藏时div div必须是100%宽度

更新时间:2023-11-30 19:57:28

也许你的意思是? DEMO

  $(#foo)。 $('#checked-a').css(width,40%); 
('#checked-a')。 $('#checked-b')。show();
});
else $('#checked-b')。slideUp('fast',function(){
$('#checked-a').css(width,100%);
});
});
});


FIXED

fixed it by editing mplungjan's code to this:

$(function() {
    $("#foo").on("click",function() {
        if ($(this).is(':checked')) $('#checked-a').show('fast',function() {
            $('#checked-b').css("width","60%");
            $('#checked-a').css("width","40%");
        }) ;
        else $('#checked-a').show('fast',function(){
           $('#checked-b').css("width","100%").show();         
           $('#checked-a').css("width","0%").hide();

        });
    });
});

i would like to have the left div to be 100% (current 60%) when right div (40%) is hidden.

screenshot with checked checkbox:

screenshot with unchecked checkbox:

now i would like to make the left div cover the whole width of the page (100%).

here is my code:

javascript:

      <script type="text/javascript">
    $(function(){
    ($('input[name = "foo"]').is(':checked'))
    $('#checked-a').slideDown('fast');
    });
  </script>

div:

    <div class="content2" id="checked-a">
    <%= yield %>
</div>

html input:

<input type="checkbox" checked="checked" name="foo" value="1" onclick="$(this).is(':checked') && $('#checked-a').slideDown('fast') || $('#checked-a').slideUp('fast');"/>

hope someone could help :)

Perhaps you mean this? DEMO

$(function() {
    $("#foo").on("click",function() {
        if ($(this).is(':checked')) $('#checked-a').slideDown('fast',function() {
            $('#checked-a').css("width","40%");
            $('#checked-b').show();
        }) ;
        else $('#checked-b').slideUp('fast',function(){
           $('#checked-a').css("width","100%");
        });
    });
});