Height of a div based on another div

0

How to leave the% div with% s with the same size as the div result777 ?

<script>
    $( "#result777" ).load(function() {
        if ( $("#publicidade").height() == "390px"){
            var altura3 = $("#publicidade").height();
        }
        else
        {
            var altura3 = "390px";
        }
    });
</script>
<script>
    $( document ).ready(function() {
        $('#result777').slimScroll({
            position: 'right',
            color: '#748392',
            height: altura3,
            width: '310px',
            railVisible: true,
            alwaysVisible: false,
            railColor: '#fff',
        });
    });
</script>
    
asked by anonymous 10.04.2014 / 03:19

4 answers

1

Considering what you said in the previous question , it seems that you are missing the concept of asynchronous operations to understand what is happening. Whenever you make a request for ajax (for example, in $( "#result777" ).load… ), the result only arrives later, and the following lines of code execute immediately. So we pass a function in ajax calls, so that it is executed only when the result arrives.

Given this, you have two options:

  • Only start slimScroll after result load arrives:

    $(document).ready(function() {
        $( "#result777" ).load(function() {
            $('#result777').slimScroll({
                position: 'right',
                color: '#748392',
                height: $("#publicidade").height(),
                width: '310px',
                railVisible: true,
                alwaysVisible: false,
                railColor: '#fff'
            });
        });
    });
    
  • Check if the slimScroll plugin provides some method to reset the height after booting, as suggested in the comments below the question and answer from Fulvio.

  • In addition, the if in your first code block does not make any sense. It tries to say: if the height of $("#publicidade") is 390 , use 390 , otherwise use 390 . Now, if it is to use 390 always, if is unnecessary.

        
    10.04.2014 / 16:35
    0

    What I did was put in the height of slimScroll $ ("# publicity"). height () ...

    <script>
    $(document).ready(function() {
        $('#result777').slimScroll({
            position: 'right',
            color: '#748392',
            height: $("#publicidade").height(),
            width: '310px',
            railVisible: true,
            alwaysVisible: false,
            railColor: '#fff',
        });
    });
    </script>
    

    Take the tests and tell us if you have solved!

        
    10.04.2014 / 03:30
    0

    I have already resolved, I had to change the height by css, so oh:

    $('.slimScrollDiv').css('height', '500px');
    

    slimscroll uses this class and can change the height thus

        
    10.04.2014 / 19:56
    0

    Save the value of the% dc_default to a variable:

    var tamanho = $('#publicidade').height();
    

    Then assign this value to div #publicidade :

    $('#result777').css('height' , tamanho);
    
        
    10.04.2014 / 22:22