试着根据父母的位置来定位孩子
Trying to position children according to where their parents are
我正在制作一个算法生成器,上面有一个主文本框,当我单击它下面的"+"时,它会将自己的副本添加到下一行。如果已经有一行,它会将其添加到该行中。问题是,我不想把它添加到下一行,我希望它位于我按下"+"符号的那一行的中心位置。有人请看一下我的代码,并给我一些关于如何解决这个问题的建议。非常感谢。
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Pathway Builder</title>
<link rel="stylesheet" href="style.css" type="text/css" />
</head>
<body>
<div id="pathway_builder">
<div class="row" id="row1">
<div class="whole">
<div class="centered_box">
<textarea class="text_field_not_selected"></textarea>
</div>
<input type="button" value="+" class="add_child not_visable" />
</div>
</div>
</div>
<script src="jQuery.js" type="text/javascript"></script>
<script src="selectors.js" type="text/javascript"></script>
</body>
</html>
javaScript/jQuery
$('textarea').live('focusin blur', function() {
$(this).toggleClass('text_field_not_selected');
});
$('.whole').live('mouseenter mouseleave', function() {
$(this).find('.add_child').toggleClass('not_visable');
});
$(document).ready(function() {
$('.add_child').live({
click: function() {
var new_row = '<div class="row"></div>'
var new_child = '<div class="whole"><div class="centered_box"><textarea class="text_field_not_selected"></textarea></div><input type="button" value="+" class="add_child not_visable" /></div>'
if ($(this).parents('.row').next().length == 0) {
$(this).parents('.row').after(new_row);
$(this).parents('.row').next().html(new_child).css('position-x', '');
} else {
$(this).parents('.row').next().append(new_child);
}
}
});
});
CSS
body {
margin: 0px;
padding: 0px;
text-align: center;
}
textarea {
width: 4em;
height: 1em;
overflow: hidden;
}
textarea:focus {
outline: none;
text-align: center;
resize: both;
padding-top: 5px;
padding-bottom: 5px;
}
.text_field_not_selected {
text-align: center;
border-radius: 10px;
-moz-border-radius: 10px;
-webkit-border-radius: 10px;
box-shadow: 0px 3px 5px #444;
-moz-box-shadow: 0px 3px 5px #444;
-webkit-box-shadow: 0px 3px 5px #444;
resize: none;
}
.pathway_builder {
text-align: center;
}
.whole {
text-align: center;
display: inline-block;
background-position-x: 100px;
}
.centered_box {
padding: 10px;
padding-bottom: 0px;
}
.add_child {
}
.not_visable {
visibility: collapse;
}
.row {
}
你想要这样的东西吗;
Fiddle:http://jsfiddle.net/Td97j/1/
演示:http://jsfiddle.net/Td97j/1/embedded/result/
相关文章:
- 在地图加载/页面加载时,我想将地图设置为当前地理位置,但不想在地图上显示定位图标
- JQuery定位:我可以滚动到正确的位置一次,但不能滚动两次
- 如何在jquerymobile中同时放置两个定位的经纬度位置
- Javascript / 根据一个元素的位置定位另一个元素
- 如何定位“隐藏”的 iframe?(应用程序:链接到嵌入“隐藏的海报图像”嵌入的 Youtube 视频的起始位置)
- 与位置的相对定位:绝对
- 在没有“位置”属性的情况下实现绝对定位,使用边距/填充
- 用于相对于用户在约束内单击的位置定位框的数学公式
- 运行地理位置定位的 js 文件
- 如果定位服务关闭,英特尔 XDK 地理位置将找不到纬度/经度
- 在 iPad 上绝对定位不会将元素设置在所需位置
- 如何使用 jQuery 计算相对定位元素的绝对位置*没有*
- 如果php返回位置头,我如何在jquery ajax中定位页面
- 试着根据父母的位置来定位孩子
- 地理定位api没有给出准确的用户位置
- 定位父元素,使子元素处于完全相同的位置
- 如何在Javascript/Mootools中根据页面上不同对象的位置定位箭头
- 使用javascript查找元素相对于最近相对定位的父元素的位置
- 多个谷歌位置请求功能(药房定位器)
- 点击html5地理定位当前位置,然后减去两点