Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jQuery-带变量的计算高度_Jquery_Css - Fatal编程技术网

jQuery-带变量的计算高度

jQuery-带变量的计算高度,jquery,css,Jquery,Css,有没有一种方法可以将calc与jQuery一起使用?我尝试了下面的方法,但似乎无效。请问有人知道正确的方法吗 var h = $('.mydiv').height(); $('.shopping-cart-table-container').css({ height: 'calc(100% - ' h')'}); 是的,您有一个小语法错误 $('.shopping-cart-table-container').css( { height: 'calc(100% - ' + h + 'px)'

有没有一种方法可以将calc与jQuery一起使用?我尝试了下面的方法,但似乎无效。请问有人知道正确的方法吗

var h = $('.mydiv').height();

$('.shopping-cart-table-container').css({ height: 'calc(100% - ' h')'});

是的,您有一个小语法错误

$('.shopping-cart-table-container').css( { height: 'calc(100% - ' + h + 'px)' } );
还可以使用反勾号使用新的模板字符串格式:

$('.shopping-cart-table-container').css( { height: `calc(100% - ${h}px)` } );

//更新:记住,jQuerys
height
函数返回没有单位的像素,因此您也需要将其添加到css语句中。

太棒了!!!我一直在寻找这些简单的解决方案。非常感谢你!下面我展示了我的代码,其中有一些更改,但目标是相同的


JS


HTML第1部分

助教 助教
HTML第2部分

名字 姓 位置 办公室 年龄 开始日期 薪水 Extn。 电子邮件 老虎 尼克松 系统架构师 爱丁堡 61 2011/04/25 $320,800 5421 Tnixon@datatables.net

HTML代码?calc是有效的css参数吗?因为就jQuery而言,你只是给css一个字符串。为什么你需要html?浏览器理解的任何css指令,你也可以用jQuery设置。这里的问题似乎是多余的
s性能
,您可能还需要添加
px
作为单位。否则,您的代码看起来不错。请花点时间阅读中的。堆栈溢出上的格式设置与其他站点不同。
var h = $('.alturainputs').height();

        $('.dynamic-height').DataTable( {
            "scrollY":        'calc(100vh - 350px - ' + h + 'px)',/*card-title-wrap bar-info height*/
            "scrollCollapse": true,
            "paging":         true
        } );