资源大全_资源网 登录

首页  php  jsp  js  java  python  .net  H5  asp  易语言  C#   jQuery  游戏  微信小程序  插件

您当前的位置:首页 > js

mootools实现可以动态调整、左右平滑拖动的分栏

2021-01-21 23:00:49  35资源网(www.35d.net)
  js
下载本资源原文网址:http://www.daima.org/js/js17201.html
本范例演示了对3栏式的网页进行宽度动态调整,用户可以用鼠标随意改变分栏的宽度,拖动过程非常的平滑,使用了mootools框架
在网页<head>区添加以下代码
[code]
<script type="text/javascript" src="js/mootools-1.2.3-core-yc.js"></script>
<script type="text/javascript" src="js/mootools-1.2.3.1-more.js"></script>
<style type="text/css">
.clear { clear:both;}
p { padding:10px;}
#message{
border:1px solid #DDD;
background:#FFFFEE;
text-align:center;
padding:4px;
min-height:20px;
margin-bottom:10px;
-moz-border-radius: 6px;
-webkit-border-radius: 6px;
}
#col_wrapper{
border:1px solid #0066cc;
position:relative;
min-height:300px;
margin-top:30px;
}
.column {
position:relative;
min-height:300px;
}
#col_1 {
position:absolute;
top:0px;
left:0px;
width:200px;
background:#ECECEC;
}
#col_2 {
position:absolute;
top:0px;
left:200px;
width:558px;
border-right:1px dotted #0066cc;
border-left:1px dotted #0066cc;
background:#EEEEEE;
}
#col_3 {
position:absolute;
top:0px;
left:760px;
width: 200px;
background:#EDEDED;
}
.column .col_title{
padding:4px;
background:#0066cc;
border-bottom:1px solid #FFF;
color:#FFF;
}
.column .col_msg{
float:right;
font-size:90%;
color:#FFF;

}
.resize {
position: absolute;
top: 26px;
right: -3px;
height: 30px;
width: 3px;
background: #666 url("images/handle.gif");
cursor: col-resize;
z-index:200;
-moz-border-radius: 2px;
-webkit-border-radius: 2px;
border: 1px solid #666;
}
</style>

<script type="text/javascript">
/*****************************************************
* Share JavaScript (//www.jb51.net)
* 使用此脚本程序,请保留此声明
* 获取此脚本以及更多的JavaScript程序,请访问 //www.jb51.net
******************************************************/
window.addEvent('domready', function() {
// define column elemnts
var col_wrap = $('col_wrapper'); // define the column wrapper so as to be able to get the total width via mootools
var col_left = $('col_1');
var col_center = $('col_2');
var col_right = $('col_3');

// define padding (seperator line widths) for column borders as defined in css
var pad = 1;

// define snap if required - set to 0 for no snap
var w_snap = 5;

var w_total = col_wrap.getWidth()-(pad*2); // total width of wrapper
var w_min = 120; // minimum width for columns
var w_min_c = w_min-(2*pad);

// define message output elements (not essential to script)
var col_1_msg = $("col_1_msg");
var col_2_msg = $("col_2_msg");
var col_3_msg = $("col_3_msg");

//show column start widths in col headers (just for show)
col_1_msg.innerHTML = col_left.getWidth()+"px";
col_2_msg.innerHTML = col_center.getWidth()+"px";
col_3_msg.innerHTML = col_right.getWidth()+"px";


// left column - affects center column position and width
col_left.makeResizable({
handle: col_left.getChildren('.resize'),
grid: w_snap,
modifiers: {x: 'width', y: false},
limit: {x: [w_min,null]},


onStart:function(el){
// get available width - total width minus right column - minimum col with
w_avail=(w_total-col_right.getWidth())-w_min;
},
onDrag: function(el) {
if(el.getWidth()>=w_avail){
// max width reached - stop drag (force max widths)
el.setStyle("width",w_avail);
}

// set center col left position
col_center.setStyle("left",col_left.getWidth());

// define and set center col width (total minus left minus right)
w_center=w_total-col_left.getWidth()-col_right.getWidth();
col_center.setStyle("width",w_center.toInt()-(pad*2));

// messages
col_1_msg.innerHTML=" "+col_left.getWidth()+"px";
col_2_msg.innerHTML=" "+col_center.getWidth()+"px";
col_3_msg.innerHTML=" "+col_right.getWidth()+"px";
},
onComplete: function() {
//could add final width to form field here
}
});

// mootools can't resize to the left so we have to resize the center column rather than the right-hand column
col_center.makeResizable({
handle: col_center.getChildren('.resize'),
grid: w_snap,
modifiers: {x: 'width', y: false},
limit: {x: [w_min_c,null]},



onStart:function(el){
// get start width so as to be able to adjust center column width
w_start=el.getWidth();

// get available width - total width minus left column - minimum col with
w_avail=w_total-col_left.getWidth()-w_min-(pad*2);
},
onDrag: function(el) {
if(el.getWidth()>=w_avail){
// max width reached - stop drag (force max widths)
el.setStyle("width",w_avail);
}else if(el.getWidth()==w_min_c){
// ensure that right col has complete available width
el.setStyle("width",w_min_c);
}


// define new left position
l_new = col_left.getWidth()+col_center.getWidth(); // force left space for right col
col_right.setStyle("left",l_new.toInt());


// define and set right column width - will always be result of left and center columns
w_new = w_total-col_left.getWidth()-col_center.getWidth();
col_right.setStyle("width",w_new.toInt());

// show messages
col_1_msg.innerHTML=" "+col_left.getWidth()+"px";
col_2_msg.innerHTML=" "+col_center.getWidth()+"px";
col_3_msg.innerHTML=" "+col_right.getWidth()+"px";
},
onComplete: function() {
//could add final width to form field here
}

});
});
</script>
[/code]
在网页<body>区添加以下代码
[code]
<div id="col_wrapper">
<div id="col_1" class="column drag_width">
<div id="col_1_title" class="col_title">&nbsp;<span id="col_1_msg" class="col_msg"></span></div>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
<div class="resize"></div>
</div>
<div id="col_2" class="column drag_width">
<div id="col_1_title" class="col_title">&nbsp;<span id="col_2_msg" class="col_msg"></span></div>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
<div class="resize"></div>
</div>
<div id="col_3" class="column">
<div id="col_1_title" class="col_title">&nbsp;<span id="col_3_msg" class="col_msg"></span></div>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
</div>
<div class="clear"></div>
</div>
<p>
<ul>
<li>Drag the column handles to adjust the column widths.</li>
<li>Uses <a href="//www.mootools.net" title="Mootools" target="_blank">Mootools</a> v1.2.3</li>
<li>See source code for implementation</li>
<li>How to use at <a href="//blog.cbolson.com/mootools-expandable-columns/" title="Back to blog">the blog</a></li>
<li>Help and Suggestions on the <a href="//forum.cbolson.com/viewforum.php?f=15" title="Need Help">forum</a></li>
</ul>
</p>
</div>
[/code]
下载地址: [ 下载地址1 ]  消耗积分:0分  [ 下载地址2 ]  消耗积分:0分
[ 下载地址3 ]  消耗积分:0分    
网盘密码 (密码:)
XmlTree树形菜单脚本实例
JavaScript实现两个多选框的移动数据项并自动排序功能
赞助
相关代码
    无相关信息
最新代码
栏目热门
Tags: 微信小程序 源码 源码下载 HTML5游戏 92Game 整站源码 PHP 商业版 帝国CMS cms 完整版 网站源码 织梦模板 织梦 wordpress插件 下载 最新 html5源码 微信小程序源码 帝国CMS内核 带后台 微信公众号 DEDECMS HTML5 完整源码 微信 自动采集 完整版源码 ecshop 源代码 Thinkphp dede织梦模板 PHP+MYSQL 小程序 小程序源码 DESTOON6.0 搜客淘宝客 淘宝客 更新包合集 带手机版 整站 手机版 完整运营版 游戏 92 92kaifa 完整商业版源码 管理系统 dedecms模板 织梦CMS内核 带数据 电影网站 系统 多城市 生成静态 免费下载 一键安装版 系统源码 多多淘宝客 同步包
资源大全_资源下载网站:www.35d.net    本站资源仅限研究学习使用,如需商用请联系版权方,     本站事务联系QQ:939804642