Ich*_*ban 1 css jquery height equation width
我试图根据容器的宽度乘以.75来设置容器的高度.
我想出了这个,但不知道我哪里出错了,因为它不起作用:
$('#slideContent').load(function() {
var wide = ('#slideContent').width()
$(this).css('height', $(this).width( wide * 0.75 ));
});
Run Code Online (Sandbox Code Playgroud)
有什么建议?
谢谢
现在试试吧.
$(document).ready(function() {
var wide = $('#slideContent').css('width');
var calculate = parseInt(wide, 10)* 0.75;
$('#slideContent').css('height', calculate);
});
Run Code Online (Sandbox Code Playgroud)
首先,我取元素的宽度并将其存储在"宽"变量中.其次,我做了一个计算变量.当从CSS样式元素中请求宽度或高度时,您将返回一个包含"px"的字符串的值,以过滤掉此"px"并使其成为整数,我使用"parseInt()"函数.",10"确保它是一个基数为10的数字.其余的应该是相当有意义的我相信.