改变和元素的宽度?

时间:2017-07-02 18:03:48

标签: javascript jquery html css

所以我想在页面变大时更改元素的宽度。 但是,如果页面宽度加倍,则t want the element的宽度增加一倍。我希望元素随着收益递减而增加。有谁知道怎么做?

1 个答案:

答案 0 :(得分:1)

您可以使用jQuery实现这一点,基本上您可以检查页面的大小,并且您应该设置元素的宽度,例如 如果您使用的是jQuery,则可以使用jQuery方法获取窗口或文档的大小:

$(window).height();   // returns height of browser viewport
$(document).height(); // returns height of HTML document (same as pageHeight in screenshot)
$(window).width();   // returns width of browser viewport
$(document).width(); // returns width of HTML document (same as pageWidth in screenshot)
For screen size you can use the screen object in the following way:

screen.height;
screen.width;

您可以使用一些方法,以下是一个示例,您可以根据页面大小设置元素的值:

var width = $(window).width(); 
$("#myElement").width(width) - 100;

我把100作为变量编号,你可以根据需要改变它。 我的意思是你可以根据自己的需要设置一个数字,以获得元素的宽度。

我希望这会对你有所帮助

相关问题