Splitter
<!DOCTYPE html>
<html>
<head>
<title>PDemo</title> </head>
<body>
<div id="test">
<div id="container" style="position:absolute; top:0px;height:535px;width:805px;left:0px; background-color:red;">
<div id="leftPanel" style="position:absolute;top:0px;width:400px;height:535px;left:0px;overflow:hidden;background-color:gray;"></div>
<div id="splitterBar" onmousedown="fnMouseDown(event,200,600,400,400);" style="padding:0px;border:0px;height:100%; left:400px;top:0;width:5px;background-color:black;cursor:w-resize;position:absolute;border-style:solid;"
></div>
<div id="rightPanel" style="position:absolute; left:405px;top:0;height:535px;width:400px;min-width:200px;max-width:600px;overflow:hidden; background-color:green;"></div>
</div>
</div>
</body>
<script type="text/javascript">
function fnMouseDown(ev,minLeftWidth,maxLeftWidth,oriLeftWidth, oriRightWidth){
var splitterBar = document.getElementById('splitterBar');
var leftPanel = document.getElementById('leftPanel');
var rightPanel = document.getElementById('rightPanel');
var container = document.getElementById('container');
var minLeftWidths = minLeftWidth;
var maxLeftWidths = maxLeftWidth;
var origianlLeftWidth = oriLeftWidth;
var originalRightWidth = oriRightWidth; var left = splitterBar.offsetLeft;
var oWidth = leftPanel.offsetWidth;
var rightLeft = rightPanel.offsetLeft;
var containerWidth = parseInt(container.style.width);
var leftPanelWidth = parseInt(leftPanel.style.width);
var rightPanelWidth = parseInt(rightPanel.style.width);
var splitterBarWidth = parseInt(splitterBar.style.width); var oEvent = ev || event;
var disX = oEvent.clientX - left;
var disForRightPanel = rightLeft - oEvent.clientX;
document.onmousemove = function (ev){
var oEvent = ev || event var currentleftWidth = oEvent.clientX - disX; if(currentleftWidth > maxLeftWidths || leftPanelWidth > maxLeftWidths){
leftPanel.style.width = origianlLeftWidth + 200 + "px";
splitterBar.style.left = origianlLeftWidth + 200 + "px";
rightPanel.style.width = rightPanelWidth - 200 + "px"; } else if(currentleftWidth < minLeftWidths || leftPanelWidth < minLeftWidths) {
leftPanel.style.width = origianlLeftWidth - 200 + "px";
splitterBar.style.left = origianlLeftWidth - 200 + "px";
rightPanel.style.width = originalRightWidth + 200 + "px";
} else {
splitterBar.style.left = oEvent.clientX - disX + 'px';
console.log("splitterBar.style.left is : " + splitterBar.style.left);
leftPanel.style.width = oEvent.clientX - disX + 'px';
//console.log("leftPanel.style.width: " + oEvent.clientX - disX +'sfsdfsdfsd');
rightPanel.style.left = oEvent.clientX - disX + splitterBarWidth + 'px';
/*rightPanel.style.width = (containerWidth - parseInt(rightPanel.style.left)) + 'px';*/
rightPanel.style.width = (containerWidth - (oEvent.clientX - disX) - splitterBarWidth) +'px';
console.log("rightPanel width" + (containerWidth - (oEvent.clientX - disX) - splitterBarWidth));
}
document.onmouseup = function (){
document.onmousemove= null;
document.onmouseup = null;
};
return false;
}; }
</script> </html>
<!DOCTYPE html>
<html>
<head>
<title>PDemo</title> </head>
<body>
<div id="test">
<div id="container" style="position:absolute; top:0px;height:535px;width:805px;left:0px; background-color:red;">
<div id="leftPanel" style="position:absolute;top:0px;width:400px;height:535px;left:0px;overflow:hidden;background-color:gray;"></div>
<div id="splitterBar" onmousedown="fnMouseDown(event,200,600,400,400);" style="padding:0px;border:0px;height:100%; left:400px;top:0;width:5px;background-color:black;cursor:w-resize;position:absolute;border-style:solid;"
></div>
<div id="rightPanel" style="position:absolute; left:405px;top:0;height:535px;width:400px;min-width:200px;max-width:600px;overflow:hidden; background-color:green;"></div>
</div>
</div>
</body>
<script type="text/javascript">
function fnMouseDown(ev,minLeftWidth,maxLeftWidth,oriLeftWidth, oriRightWidth){
var splitterBar = document.getElementById('splitterBar');
var leftPanel = document.getElementById('leftPanel');
var rightPanel = document.getElementById('rightPanel');
var container = document.getElementById('container');
var minLeftWidths = minLeftWidth;
var maxLeftWidths = maxLeftWidth;
var origianlLeftWidth = oriLeftWidth;
var originalRightWidth = oriRightWidth; var left = splitterBar.offsetLeft;
var oWidth = leftPanel.offsetWidth;
var rightLeft = rightPanel.offsetLeft;
var containerWidth = parseInt(container.style.width);
var leftPanelWidth = parseInt(leftPanel.style.width);
var rightPanelWidth = parseInt(rightPanel.style.width);
var splitterBarWidth = parseInt(splitterBar.style.width); var oEvent = ev || event;
var disX = oEvent.clientX - left;
var disForRightPanel = rightLeft - oEvent.clientX;
document.onmousemove = function (ev){
var oEvent = ev || event var currentleftWidth = oEvent.clientX - disX; if(currentleftWidth > maxLeftWidths || leftPanelWidth > maxLeftWidths){
leftPanel.style.width = origianlLeftWidth + 200 + "px";
splitterBar.style.left = origianlLeftWidth + 200 + "px";
rightPanel.style.width = rightPanelWidth - 200 + "px"; } else if(currentleftWidth < minLeftWidths || leftPanelWidth < minLeftWidths) {
leftPanel.style.width = origianlLeftWidth - 200 + "px";
splitterBar.style.left = origianlLeftWidth - 200 + "px";
rightPanel.style.width = originalRightWidth + 200 + "px";
} else {
splitterBar.style.left = oEvent.clientX - disX + 'px';
console.log("splitterBar.style.left is : " + splitterBar.style.left);
leftPanel.style.width = oEvent.clientX - disX + 'px';
//console.log("leftPanel.style.width: " + oEvent.clientX - disX +'sfsdfsdfsd');
rightPanel.style.left = oEvent.clientX - disX + splitterBarWidth + 'px';
/*rightPanel.style.width = (containerWidth - parseInt(rightPanel.style.left)) + 'px';*/
rightPanel.style.width = (containerWidth - (oEvent.clientX - disX) - splitterBarWidth) +'px';
console.log("rightPanel width" + (containerWidth - (oEvent.clientX - disX) - splitterBarWidth));
}
document.onmouseup = function (){
document.onmousemove= null;
document.onmouseup = null;
};
return false;
}; }
</script> </html>
<html>
<head>
<title>Splitter Control</title>
</head>
<script src="../package/reactjs/react.js"></script>
<script src="../package/reactjs/JSXTransformer.js"></script>
<style type="text/css">
.container {
width: 605px;
height: 300px;
height: 300px;
margin: 0 auto 0 auto;
margin-top: 50px;
border: solid 1mm yellow;
}
.left-panel {
width: 300px;
height: 300px;
float: left;
background: grey;
}
.right-panel {
width: 300px;
height: 300px;
float: right;
background: green;
} </style>
<body>
<div id="container" class="container">
<div id="leftPanel" class="left-panel">Left</div>
<div id="rightPanel" class="right-panel">Right</div>
</div>
<script type="text/jsx">
var disX = 0;
var isBegin = false;
var Splitter = React.createClass({
getInitialState: function()
{
var left = document.getElementById(this.props.leftPanel);
var right = document.getElementById(this.props.rightPanel);
left.style.width = "100%";
right.style.width = "100%";
right.style.height = "100%";
return {
originalLeftWidth: this.props.originalLeftWidth,
originalLeftHeight: this.props.originalLeftHeight,
originalSplitterWidth: this.props.originalSplitterWidth,
originalSplitterHeight: this.props.originalSplitterHeight,
originalRightWidth: this.props.originalRightWidth,
originalRightHeight: this.props.originalRightHeight,
currentLeftWidth: this.props.originalLeftWidth,
currentSplitterLeft: this.props.originalLeftWidth,
currentRightWidth: this.props.originalRightWidth,
currentRightLeft: this.props.originalLeftWidth + this.props.originalSplitterWidth,
leftPanel: left,
rightPanel:right,
currentSplitterBackgroundColor: 'blue'
};
}, onMouseMove: function(ev){
ev.preventDefault();
if(isBegin == true)
{
var currLeftWidth = ev.clientX - disX;
if(currLeftWidth > this.props.maxLeftWidth || this.state.currentLeftWidth > this.props.maxLeftWidth)
{
var cuRightWidth = this.props.originalRightWidth + this.props.originalLeftWidth - this.props.maxLeftWidth;
this.setState({
currentLeftWidth:this.props.maxLeftWidth,
currentSplitterLeft:this.props.maxLeftWidth,
currentRightWidth:cuRightWidth,
currentSplitterBackgroundColor: 'black'
});
} else if(currLeftWidth < this.props.minLeftWidth || this.state.currentLeftWidth < this.props.mixLeftWidth) {
var cuRightWidth = this.props.originalRightWidth + this.props.originalLeftWidth - this.props.minLeftWidth;
this.setState({
currentLeftWidth:this.props.minLeftWidth,
currentSplitterLeft:this.props.minLeftWidth,
currentRightWidth:cuRightWidth,
currentSplitterBackgroundColor: 'black'
});
} else {
var cuRightWidth = this.props.originalLeftWidth + this.props.originalRightWidth - currLeftWidth;
this.setState({
currentLeftWidth:currLeftWidth,
currentSplitterLeft:currLeftWidth,
currentRightWidth:cuRightWidth,
currentSplitterBackgroundColor: 'black'
});
}
}
}, onMouseUp: function(){
isBegin = false;
disX = 0;
this.setState({
currentSplitterBackgroundColor: 'blue'
});
document.body.removeEventListener("mouseup", this.onMouseUp);
document.body.removeEventListener("mousemove", this.onMouseMove);
}, onMouseOver: function(){
this.setState({
currentSplitterBackgroundColor: 'black'
});
}, onMouseOut: function(){
this.setState({
currentSplitterBackgroundColor: 'blue'
});
}, onMouseDown: function(ev){
isBegin = true;
var splitter = React.findDOMNode(this.refs.splitter);
disX = ev.clientX - splitter.offsetLeft;
document.body.addEventListener("mouseup", this.onMouseUp);
document.body.addEventListener("mousemove", this.onMouseMove);
}, componentDidMount: function()
{
this.left= this.refs.left.getDOMNode();
this.right = this.refs.right.getDOMNode();
this.left.appendChild(this.state.leftPanel);
this.right.appendChild(this.state.rightPanel);
}, render: function()
{
return(
<div style={{position:'relative'}}>
<div id="message-list" ref="left" style={{ float:'left',
width:this.state.currentLeftWidth,
height:this.state.originalLeftHeight}}>
</div>
<div ref="splitter" className='splitter'
style={{
left:this.state.currentSplitterLeft,
height:this.state.originalSplitterHeight,
width:this.props.originalSplitterWidth,
backgroundColor: this.state.currentSplitterBackgroundColor,
float: 'left'
}}
onMouseDown={this.onMouseDown}
onMouseOver={this.onMouseOver}
onMouseOut={this.onMouseOut}>
</div>
<div ref="right" id="right-panel" style={{float:'left',
overflow: this.props.overflow,
width:this.state.currentRightWidth,
height:this.state.originalRightHeight}}>
</div>
</div>
);
}
}); React.render(
<Splitter
originalLeftWidth={300}
originalLeftHeight={300}
originalSplitterWidth={5}
originalSplitterHeight={300}
originalRightWidth={300}
originalRightHeight={300}
minLeftWidth={200}
maxLeftWidth={400}
leftPanel={"leftPanel"}
rightPanel={"rightPanel"}
overflow ={"auto"} />,
document.getElementById("container")
);
</script>
</body>
</html> 来自 网易手机号码邮箱 -- 有手机就有网易手机号码邮箱,了解详情>
Splitter的更多相关文章
- Ultra Video Splitter & Converter
1. Video Splitter http://www.aone-soft.com/splitter.htm Ultra Video Splitter 是一款视频分割工具.可将一个巨大的AVI/Di ...
- guava之Joiner 和 Splitter
最近在给客户准备一个Guava的分享,所以会陆续的更新关于Guava更多的细节分享.本文将记录Guava中得字符串处理Joiner(连接)和Splitter(分割)处理. Joiner 首先我们来看看 ...
- guava--Joiner、Splitter、MapJoinner、MapSplitter
Joiner: List<String> stringList = new ArrayList<String>(); stringList.add("aa" ...
- angular的splitter案例学习
angular的splitter案例学习,都有注释了,作为自己的备忘. <!DOCTYPE html> <html ng-app="APP"> <he ...
- Google Guava学习笔记——基础工具类Splitter的使用
另一项经常对字符串的操作就是根据指定的分隔符对字符串进行分隔.我们基本上会使用String.split方法: String testString = "Monday,Tuesday,,Thu ...
- Data Flow ->> CDC Control Task, CDC Source, CDC Splitter
CDC Control Task可以从控制CDC数据同步,比如初始化加载.LSN范围的管理.它可以代替另一种做法,就是通过调用一批CDC函数来完成同样的事情.从SSIS的角度来完成,事情编程简单,和另 ...
- Google Guava的splitter用法
google的guava库是个很不错的工具库,这次来学习其spliiter的用法,它是一个专门用来 分隔字符串的工具类,其中有四种用法,分别来小结 1 基本用法: String str = " ...
- Google的Guava工具类splitter和apache stringutil对比 编辑
一直用的是apache的stringutil工具类,其实google的工具类项目 guava中居然也有字符串的分隔类splitter的,在 http://code.google.com/p/guava ...
- c# splitter控件使用简介
摘自:http://blog.itpub.net/26221264/viewspace-735903 1.先在窗体上放置部分一的控件,这里是TreeView控件,然后把它的 Dock 属性设置为 Le ...
随机推荐
- mac下修改mysql登录密码
mysql版本5.7.9 在mac终端下修改mysql用户登录密码 终端命令如下: update mysql.user set authentication_string=PASSWORD(" ...
- Linux下MySQL主从同步配置
Centos6.5 MySQL主从同步 MySQL版本5.6.25 主服务器:centos6.5 IP:192.168.1.101 从服务器:centos6.5 IP:192.168.1.102 一. ...
- 解决cell循环利用造成的重复勾选
@interface ProfessionViewController (){ NSMutableArray *_professionArray;//cell模型数组 NSMutableArray * ...
- 各种LICENSE的作用--GET
许 多开发者和设计者希望把他们的作品作为开源项目共享,他们希望其他人能够利用和共享他们的代码. 而各种开源社区就是因为这个原因而充满活力.开源软件可以用于你能想象得到的任何应用程序,许多web设计人员 ...
- 20101102--SQL字符串函数 ,日期和时间函数
--------------------字符串函数------------------------- --ASCII 返回字符串的首字母的ASCII编码 select ASCII('w') selec ...
- 8款超绚丽的jQuery焦点图动画
随着前端技术和浏览器技术的不断发展,人们开始对网页视觉效果的要求越来越高.我们经常会在页面中看到很多炫酷的图片焦点图播放控件,有些甚至是大屏的焦点图占用大片的页面空间,从而吸引用户的眼球.本文要分享的 ...
- 反射-Reflect
1.得到一份Class(同一个类在JVM中只有一份字节码) 三种方式:类名.class, Class.forName("全限定名");, 对象.getClass(); 基本类型 i ...
- JAVA作业-1
编写一个程序,用户输入两个数,求出其加减乘除,并用消息框显示计算结果. import javax.swing.JOptionPane; // import class JOptionPane publ ...
- gcc与g++的区别
一:gcc与g++比较 编译c/c++代码的时候,有人用gcc,有人用g++,于是各种说法都来了,譬如c代码用gcc,而 c++代码用g++,或者说编译用gcc,链接用g++,一时也不知哪个说法正确, ...
- C# 中有关 using 关键字
关于 C# 中的 using 关键字 我们往往只在代码的开头使用 using 关键字来引入名称空间,这是 using 的一个最常见的使用. 但是,using 关键字是否只有这么一处用武之地吗? 下面, ...