Resize when clicking on toggle

Asked

Viewed 133 times

0

Does anyone know how I can resize div parent by clicking on a toggle, which in this case opens a div eldest daughter?

Within the div #g-intro I have a class that opens the content and exceeds the screen size. I use this function so that the div occupy the entire screen, but don’t keep increasing or decreasing on the mobile device because of the Chrome bar.

Code:

       (function($) {
var isMobile = /iPhone|iPad|iPod|Android/i.test(navigator.userAgent);
if(isMobile && window.matchMedia("(orientation: portrait)").matches){
    function AllHeight( elem ) {

    var altura  = $( window ).height() + "px";
    var altura2 = $("#g-valores).height();
    $( elem ).css({
        height: altura
    });}
$( window ).on( "load size", function() {
    AllHeight( "#uppercg, #upper,#g-intro" );
});}
  • $("#g-valores).height(); - is missing a " here.

  • thanks, I got it, but I was going to try to do an if to catch the bigger height, not rolling hehe

2 answers

0

<section id="g-intro" class="metade size-flex">
                <div class="g-container">                        
    <div class="g-block hidden-desktop g-block-flex size-100">
   <div class="g-content g-particle">
<div class="sample-content">
        <div class="g-grid">
            <div class="g-block">
                <div class="g-content">
<div class="sample-description"></div>
</div>
</div>
<div class="g-grid">
</div>
</div>       
</div>                  
</div>        
</div>
<div class="g-grid">
<div class="g-block g-block-flex center size-100">
<div class="g-content g-particle">
<button type="button" id="b-valores" class="button-valores" data-element="#g-valores">NOSSOS VALORES</button>
<div class="content-servico">
<div id="g-valores">
<div class="g-content-valores">
<div class="g-grid">
<div class="g-block">
<div class="g-content">
</div>
</div>
</div>
</div>
</div>
<div class="g-content-valores">
<div class="g-grid">
<div class="g-block">
<div class="g-content">
</div>
</div>
</div>
</div>
</div>
<div class="g-content-valores">
<div class="g-grid">
<div class="g-block">
<div class="g-content">
</div>
</div>
</div>
</div>
</div>
<div class="g-content-valores">
<div class="g-grid">
<div class="g-block">
<div class="g-content">
</div>
</div>
</div>
</div>
</div>
<div class="g-content-valores">
<div class="g-grid">
<div class="g-block">
<div class="g-content">
</div>
</div>
</div>
</div>
</div>
<div class="g-content-valores">
<div class="g-grid">
<div class="g-block">
<div class="g-content">
</div>
</div>
</div>
</div>
</div>
<div class="mask">
</div>
</div>
</div>          
</div>                    
</div>
</div>
</div>
</section>

CSS

#g-valores{margin-left:0;float:left; position:relative; display: none;}

JS

    (function($) {
    var isMobile = /iPhone|iPad|iPod|Android/i.test(navigator.userAgent);
    if(isMobile && window.matchMedia("(orientation: portrait)").matches){
        function AllHeight( elem ) {

        var altura  = $( window ).height() + "px";

        $( elem ).css({
            height: altura
        });}


    $( window ).on( "load size", function() {
        AllHeight( "#uppercg, #upper,#g-intro" );
    });
    } else if(isMobile && window.matchMedia("(orientation: landscape)").matches){
        function AllHeightLand( elem ) {
        var altura  = $( window ).height() + "px";

        $( elem ).css({
            height: altura
        });
            }
    $( window ).on( "load size", function() {
        AllHeightLand( "#uppercg, #upper,#g-intro" );
    });
    }

    window.addEventListener("orientationchange", function() {                   
        if (window.matchMedia("(orientation: portrait)").matches) {
            window.addEventListener("resize", function () { 
            location.reload();
        }, false);
         }
        if (window.matchMedia("(orientation: landscape)").matches) {
            window.addEventListener("resize", function () { 
            location.reload();
        }, false);
         }
    }, false);})(jQuery);

(function($) {
$(function(){
    $(".button-valores").click(function(e){
        e.preventDefault();
        el = $(this).data('element');
        $(el).slideToggle('slow');
});
});})(jQuery);

0

I understand you want to leave the #g-intro always with the height of the screen.

In that case, to open a div larger inside, this should adjust to the size of #g-introand have in the css the attribute overflow-y: auto

I adapted to try to exemplify here.

 var limite = $('#g-intro');

limite.height(200);//simula o que a função AllHeight faz

$(".button-valores").click(function (e) {

     el = $(this).data('element');
    
//ajusta a div filha à altura limite
     $(el).css({'height': ( limite.height() - $(this).outerHeight() )+ 'px', 'width': limite.width() + 'px'}).slideToggle('slow');
        });
#g-intro {background-color:#ffff00; border: 1px solid #ff0000}  

#g-valores{margin-left:0;float:left; position:relative; display: none; color: #fff; background-color:#000;  overflow-y: auto;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<section id="g-intro" class="metade size-flex">
    <div class="g-container">
        <div class="g-block hidden-desktop g-block-flex size-100">
            <div class="g-content g-particle">
                <div class="sample-content">
                    <div class="g-grid">
                        <div class="g-block">
                            <div class="g-content">
                                <div class="sample-description"></div>
                            </div>
                        </div>
                        <div class="g-grid">
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="g-grid">
            <div class="g-block g-block-flex center size-100">
                <div class="g-content g-particle">
                    <button type="button" id="b-valores" class="button-valores" data-element="#g-valores">NOSSOS VALORES</button>
                    <div class="content-servico">
                        <div id="g-valores">
                            <div class="g-content-valores">
                                <div class="g-grid">
                                    <div class="g-block">
                                        <div class="g-content">
                                            conteudo<br /><br />
                                            conteudo<br /><br />
                                            conteudo<br /><br />
                                            conteudo<br /><br />
                                            conteudo<br /><br />
                                            conteudo<br /><br />
                                            conteudo<br /><br />
                                            conteudo<br /><br />
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
               
                    </div>
       
                </div>
    
            </div>
   
        </div>

    </div>
    <div class="mask">
    </div>
    
</section>

  • That’s pretty much it. The structure looks like this: <Section id="g-intro"> <button type="button" class="button-values" data-element="#g-values">OUR VALUES</button> <div class="content-service"> <div id="g-values"> <div class="g-content-values"> <div;<class="g-grid"> ... There I have the function to catch the #g-intro by the screen size, only the content of . g-values surpasses and has a height:auto; =\

  • @Romulo, if you can adapt for a code and post here for us to take a look.

  • I put html in the css of div and js full :)

  • @Romulo, I can’t find the code section responsible for Toggle.

  • I edited, this below the function of dimensioning the Divs.

  • @Romulo, I don’t know if this is what you want, but I edited the code of my answer.

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.