2017-07-02 109 views
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作为一个可变数字,你可以发言按照你的意愿去做。 我的意思是你可以放一个数字,只要你想得到你想要的宽度。我希望这对您有所帮助