【发布时间】:2012-08-29 13:52:33
【问题描述】:
【问题讨论】:
-
你想使用什么 html?你能在 jsFiddle(jsfiddle.ne) 上创建一个演示吗
【问题讨论】:
是的,这当然是可能的。那里可能有一个 JQuery 或 MooTools 插件可以做到这一点。否则,我为您提供了一个使用 JQuery 的简单示例,您可以使用它。见this JSFiddle。
HTML 基本上是这样的:
<div id="left">Left column!</div>
<div id="verticalresizer"> </div>
<div id="right">Right column!</div>
然后它们被绝对定位(为简单起见,示例剪切中的额外 CSS):
html, body {
height: 100%;
}
#left {
width: 200px; /* default starting width */
position: absolute;
top: 0;
bottom: 0;
left: 0;
}
#right {
position: absolute;
top: 0;
bottom: 0;
right: 0;
left: 204px; /* width of left col + 4 pixel wide resizer */
}
#verticalresizer {
background-color: black; /* so it can be seen */
width: 4px;
height: 100%;
cursor: col-resize;
position: absolute;
top: 0;
left: 200px; /* width of left col */
bottom: 0;
}
然后是 JavaScript。先解释一下。代码几乎都在监听用户点击垂直调整大小。一旦发生这种情况,它就会监听鼠标的移动。每次鼠标移动时,相应地调整列的大小并将滑块保持在鼠标下方。当用户松开鼠标(mouseup)时,停止监听/调整大小。
var left = 200; // starting left col width
var isClicked = false;
var startX = 200; // starting horizontal position of resizer bar
var isMouseDown = false;
// attach listeners to the document itself
$(document).mousedown(function() {
isMouseDown = true;
}).mouseup(function() {
isMouseDown = false;
}).mousemove( function(event) {
if (isClicked && isMouseDown) {
var newX = event.pageX;
if (startX != newX) {
left += (newX - startX);
if (left < 0) {
left = 0; // keep from moving the slider beyond the left edge of the screen
newX = 0;
}
setWidthOfLeftColumn( left );
startX = newX;
}
}
});
// attach click listeners to the resizer slider
$("#verticalresizer").mousedown( function(event) {
isClicked = true;
startX = event.pageX;
}).mouseup( function (event) {
isClicked = false;
});
// function to resize everything
function setWidthOfLeftColumn( value ) {
$("#left").css("width", "" + left + "px");
$("#right").css("left", "" + (left + 4) + "px");
$("#verticalresizer").css("left", "" + left + "px");
}
【讨论】:
尝试使用 HTML 框架集标签。
【讨论】: