[英]Change li height on browser width resize
I made a little script to change the height of a group of li-elements to the one with the most content. 我编写了一个小脚本,将一组锂元素的高度更改为内容最多的锂元素。
The code works fine, but it should also work by resizing the browser width. 该代码可以正常工作,但也应该通过调整浏览器的宽度来工作。
I need to know why it doesn't reload by changing the browser width ? 我需要知道为什么不通过更改浏览器宽度来重新加载?
Here is my Code : 这是我的代码:
//changes slider hight to the hight of the li with the most content
function heightChange() {
var max = -1;
$(".feedback li").each(function() {
var h = $(this).height();
max = h > max ? h : max;
});
$(".feedback li").css("height", max);
};
// start by open site
heightChange();
// load function by resizing of the browser window
$(window).bind("resize", function(){
heightChange();
});
You need to reset your height before setting it again. 您需要先重新设置高度,然后再进行设置。 Demo 演示
$(window).on("resize", function(){
$(".feedback li").css("height", "auto");
heightChange();
});
Otherwise will height()
just return the specified value; 否则, height()
只会返回指定的值;
Also, .on()
is the preferred way to bind and event, as of jQuery 1.7 另外,从jQuery 1.7开始, .on()
是绑定和事件的首选方式
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.