Javascript 在一系列浮动中创建/删除行:左div
我有一个div元素列表,所有元素都带有float:left,像这样一个接一个Javascript 在一系列浮动中创建/删除行:左div,javascript,jquery,html,css,dom,Javascript,Jquery,Html,Css,Dom,我有一个div元素列表,所有元素都带有float:left,像这样一个接一个 <div id="container"> <div id=0" style="float:left;> Stuff </div> <div id=1" style="float:left;> Stuff </div> <div id=2" style="float:left;> Stuff </div> ...
<div id="container">
<div id=0" style="float:left;> Stuff </div>
<div id=1" style="float:left;> Stuff </div>
<div id=2" style="float:left;> Stuff </div>
...
<div id=n" style="float:left;> Stuff </div>
</div>
东西
东西
东西
...
东西
我正在努力实现以下目标:
如果我单击其中一个div,它会将周围的div(左侧的向上和右侧的向下)推开,并填充自己的行。然后,当再次单击时,它将返回到原始配置
我的尝试:
谢谢你的时间 我想你想要实现这一点,请检查一下
var divWidth=250;
var n=5//这将不是一个内部div
$(函数(){
$('#container div')。每个(函数(索引,元素){
$(此)。单击(函数(e){
if($(this).width()==divWidth)
{
var dt=宽度;
如果(索引!=0)
{
$(this.prev().hide();
dt+=宽度;
}
else if(索引
var parentWidth = $("#container").css("width");
var originalWidth = $($("#container div")[0]).css("width");
$("#container div").click(function(){
if($(this).css("width") != parentWidth) {
$(this).css("width",parentWidth);
}
else {
$(this).css("width",originalWidth);
}
});
var divWidth = 250;
var n= 5; //this will be no of inner divs
$(function(){
$('#container div').each(function(index, element) {
$(this).click(function(e) {
if($(this).width() == divWidth)
{
var dt = divWidth;
if(index != 0)
{
$(this).prev().hide();
dt += divWidth;
}
else if(index < n)
{
$(this).next().hide();
dt += divWidth;
}
$(this).width(dt);
}
else
{
$(this).width(divWidth);
if(index != 0)
{
$(this).prev().show();
}
else if(index < n)
{
$(this).next().show();
}
}
});
});
});