How to set top position using jquery

后端 未结 5 651
一向
一向 2021-02-04 23:22

I am creating custom div scroller and want to set top position of content div. My jquery code is as below:

containerOuterHeight=$(\"#messagePopUpContainer\").out         


        
5条回答
  •  不思量自难忘°
    2021-02-04 23:43

    You could also do

       var x = $('#element').height();   // or any changing value
    
       $('selector').css({'top' : x + 'px'});
    

    OR

    You can use directly

    $('#element').css( "height" )
    

    The difference between .css( "height" ) and .height() is that the latter returns a unit-less pixel value (for example, 400) while the former returns a value with units intact (for example, 400px). The .height() method is recommended when an element's height needs to be used in a mathematical calculation. jquery doc

提交回复
热议问题