我在$(window).resize()上有一个脚本,它需要在列表中隐藏div。但是,因为我使用的是较旧的操作系统,所以我的浏览器不能实时调整大小。相反,它会留下一个轨迹,它将调整大小,然后打开,松开,它将调整大小。因此,下面的脚本只从列表中删除了一个div,而不是所有的冲突。我该如何解决这个问题呢?
jQuery:
$(window).resize(function () {
movePivots();
});
function movePivots() {
var last_pivot = $("ul li:last");
if ($("#container").width() - $("ul").width() <= 0) {
last_pivot.remove();
} else {
}
}CSS:
#container
{
float: left;
width: 50%;
min-width: 450px;
max-width: 900px;
height: 1000px;
background-color: #eee;
}
#nav
{
float: left;
background-color: #ddd;
min-width: 450px;
max-width: 900px;
width: 100%;
}
ul
{
float: left;
margin: 0;
padding: 0;
list-style: none;
background-color: #ccc;
}发布于 2012-07-12 07:41:29
使用while循环:
$(window).resize(function () {
movePivots();
});
function movePivots() {
var last_pivot = $("ul li:last");
while ($("#container").width() - $("ul").width() <= 0) {
last_pivot.remove();
last_pivot = $("ul li:last");
}
}https://stackoverflow.com/questions/11443128
复制相似问题