我正在尝试使用 .animate() 函数(我用粗体标记)从右到左滑动一系列分区,这是有效的。但是,我无法向后滚动到左侧,因为看起来将保持分区的左侧宽度已放置在右侧,这实际上是空白空间。
这是CSS:
div.folders-hierarchy {
border: 1px dotted #ccc;
border-radius: 5px;
height: 300px;
margin: 10px 0;
padding: 0 0 0 0;
overflow: auto;
width: 325px;
-moz-border-radius: 5px;
}
div.folders-hierarchy .container-folders {
right: 0px;
position: relative;
width: 0px;
}
div.folders-hierarchy .container-folders .container-folder {
float: left;
width: 325px;
}
div.folders-hierarchy ul {
margin: 0 5px;
width: 315px;
}
div.folders-hierarchy ul input[type="radio"] {
margin: 0 2px;
}
div.folders-hierarchy ul li {
border: 1px solid #ccc;
border-radius: 5px;
list-style-type: none;
margin: 5px 0;
padding: 5px 10px;
}
这是HTML:
<div class="folders-hierarchy">
<div class="container-folders"></div>
</div>
这是jQuery:
$(document).ready(function(){
var folders = new Object();
var levels = new Object();
var id;
var container = 325;
var slide = 0;
levels.index = 0;
folders.chosen = (folders.chosen == null) ? 0 : folders.chosen;
$(".folders-hierarchy").delegate('li a', 'click', function(event) {
event.preventDefault();
id = parseInt($(this).attr("data-folder"));
levels.chosen = parseInt($(this).closest('ul').attr("data-levels"));
folders.chosen = id;
if (levels.chosen < levels.index) {
if (levels.index > 1) {
x = (levels.index+1);
for (var i=0;i<x;i++) {
if (i > levels.chosen) {
$('[data-levels="' + i + '"]').parent().remove();
}
}
} else {
$('[data-levels="1"]').parent().remove();
}
levels.index = (levels.chosen+1);
} else {
levels.index++;
}
$(".container-folders").css('width', (container = (container+325)) + 'px');
**$(".container-folders").animate( { right: slide = (levels.index < 1) ? 325 : (slide+325) }, 250);**
get_folders_hierarchy(folders);
})
function get_folders_hierarchy (folders) {
$.ajax({
url: base_url + "folders/jq_get_folders_hierarchy/" + folders.chosen,
contentType: "application/json; charset=utf-8",
dataType: "json",
cache: false,
success: function (element) {
$("div.container-folders").append('<div class="container-folder"><a name="level-' + levels.index + '"></a><ul id="folders-hierarchy-' + folders.chosen + '" data-levels="' + levels.index + '">');
if (element!=null) {
for (var i=0;i<element.length;i++) {
$("#folders-hierarchy-" + folders.chosen).append('<li><input type="radio" value="' + element[i].child + '" name="folders[]" /><a href="#level-' + (levels.index+1) + '" data-folder="' + element[i].child + '">' + element[i].name + '</a></li>');
if (i==(element.length)-1) {
folders.chosen = element[i].parent;
}
}
} else {
$("#folders-hierarchy-" + folders.chosen).append('<li><input type="radio" value="' + folders.chosen + '" name="folders[]" />Choose this Folder</li>');
}
$("div.container-folders").append('</ul></div>');
}
});
}
get_folders_hierarchy(folders);
});
我怀疑它是一个浮动或什么的,但我只是看不出是哪个,在哪里,或者——更重要的是——为什么。
另外,这里是代码。但是,由于数据的组合方式,提供 JSON 数据是不切实际的。