一区二区久久-一区二区三区www-一区二区三区久久-一区二区三区久久精品-麻豆国产一区二区在线观看-麻豆国产视频

js 分欄效果實(shí)現(xiàn)代碼

網(wǎng)上我也見(jiàn)到一些分欄效果,也有一個(gè)jquery的插件jquery.splitter.js, 但是他們基本都沒(méi)有解決一個(gè)問(wèn)題:如果頁(yè)面上有iframe, 當(dāng)拖動(dòng)分割線經(jīng)過(guò)iframe的時(shí)候,鼠標(biāo)不聽(tīng)使喚了,我曾經(jīng)開(kāi)過(guò)帖子討論過(guò)這個(gè)問(wèn)題。本例采用一個(gè)小技巧解決了這個(gè)問(wèn)題,使拖動(dòng)流暢。
復(fù)制代碼 代碼如下:
<html>
<head>
<title>Splitter demo</title>
<style>
            #splitter_container{
             width: 100%;
             height: 100%;
             border: solid #eee 1px;
             margin: 0px;
             padding: 0px;
             overflow: hidden;
            }
            #splitter_left_panel{
             width: 300px;
             height: 100%;
             float: left;
             border: solid blue 0px;
            }
            #splitter_bar{
             width: 8px;
             height: 100%;
             float: left;
             background-color: #ccc;
             cursor: col-resize;
            }
            #splitter_right_panel{
             height: 100%;
             padding-top: 10px;
            }
</style>
<script>
/*
* splitter.js
* author: sunxing007
* http://blog.csdn.NET/sunxing007
* date: 08/26/2009

**************************************************************************************
The css script below is needed for the html page when using splitter.js, please save
it as splitter.css, and modify it carefully.
**************************************************************************************
#splitter_container{
width: 100%;
height: 100%;
border: solid #eee 1px;
margin: 0px;
padding: 0px;
overflow: hidden;
}
#splitter_left_panel{
width: 300px;
height: 100%;
float: left;
border: solid blue 0px;
}
#splitter_bar{
width: 8px;
height: 100%;
float: left;
background-color: #ccc;
cursor: col-resize;
}
#splitter_right_panel{
height: 100%;
padding-top: 10px;
}
**************************************************************************************
How to use this splitter?
**************************************************************************************
<!--
     <html>
<head>
<title>Splitter demo</title>
<link href="splitter.css" type="text/css" rel="stylesheet" />
<script src="splitter.js"></script>
</head>
<body onload="Splitter.init({id: 'splitter_Container'});">
<div id="splitter_container">
<div id="splitter_left_panel">
left panel
<!--you can put any html code here-->
</div>
<div id="splitter_bar"></div>
<div id="splitter_right_panel">
right panel
<!--you can put any html code here-->
</div>
</div>
</body>
</html>
-->
**************************************************************************************
*/

/** this is a helper function used to get the dom element specified by id **/

function $(id){return document.getElementById(id);}

/** the main functionality of splitter **/

var Splitter = {
    container: null,
    lPanel: null,
    rPanel: null,
    bar: null,
movingBar: null,
//左面板初始,最大,最小寬度
    lPanelInitWidth: '250px',
    lPanelMaxWidth: '500px',
    lPanelMinWidth: '200px',
    rPanelInitWidth: '800px',
    rPanelMaxWidth: '999px',
    rPanelMinWidth: '500px',
    //分隔線被拖動(dòng)的時(shí)候的顏色
    barActiveColor: '#0080ff',
    //左面的面板是否設(shè)置最大/最小寬度
    isWidthLimit: true,
    init: function(config){
if(!config.id){
alert('Can not initialize splitter.');
return;
}
if($(config.id)){
this.container = $(config.id);
if(!($('splitter_left_panel')&&$('splitter_right_panel')&&$('splitter_bar'))){
alert('Can not initialize splitter.');
return;
}
else{
this.lPanel = $('splitter_left_panel');
this.rPanel = $('splitter_right_panel');
this.bar = $('splitter_bar');
}
}

if(config.lPanelMaxWidth){
this.lPanelMaxWidth = config.lPanelMaxWidth;
}
if(config.lPanelMinWidth){
this.lPanelMinWidth = config.lPanelMinWidth;
}
if(config.rPanelMaxWidth){
this.rPanelMaxWidth = config.rPanelMaxWidth;
}
if(config.rPanelMinWidth){
this.rPanelMinWidth = config.rPanelMinWidth;
}
if(config.lPanelInitWidth){
this.lPanelInitWidth = config.lPanelInitWidth;
}
if(config.rPanelInitWidth){
this.rPanelInitWidth = config.rPanelInitWidth;
}
if(config.barActiveColor){
this.barActiveColor = config.barActiveColor;
}
//alert(typeof(config.isWidthLimit));
if(config.isWidthLimit!=undefined){
this.isWidthLimit = config.isWidthLimit;
}
var mask = document.createElement('div');
document.body.appendChild(mask);
with(mask.style){
position = 'absolute';
left = '0px';
top = '0px';
zIndex = 900;
width = '100%';
height = '100%';
display = 'none';
backgroundColor = '#ccc';
filter = 'alpha(opacity=10)';
}
//background-color:red;filter:alpha(opacity=60)
Splitter.mask = mask;
this.bar.onmousedown = Splitter.start;
    },
    start: function(){
var o = Splitter.container;
o.lastMouseX = event.x;
Splitter.mask.style.display = '';
var movingBar = document.createElement('div');
Splitter.container.appendChild(movingBar);
with(movingBar.style){
position = 'absolute';
left = Splitter.bar.offsetLeft + 'px';
top = '0px';
width = Splitter.bar.currentStyle.width;
height = '100%';
backgroundColor = Splitter.barActiveColor;
zIndex = 999;
cursor = 'col-resize';
}
movingBar.dx = 0;
Splitter.movingBar = movingBar;
document.onmousemove = Splitter.move;
document.onmouseup = Splitter.end;
    },
    move: function(){
var o = Splitter.container;
var dx = event.x - o.lastMouseX;
Splitter.movingBar.dx = Splitter.movingBar.dx + dx;
var left = parseInt(Splitter.movingBar.style.left) + dx;
Splitter.movingBar.style.left = left;
o.lastMouseX = event.x;
    },
    end: function(){
document.onmousemove = null;
document.onmouseup = null;
Splitter.mask.style.display = 'none';
var dx = Splitter.movingBar.dx;
Splitter.container.removeChild(Splitter.movingBar);
var w = parseInt(Splitter.lPanel.currentStyle.width) + dx;
if(Splitter.isWidthLimit){
        var _width = (w > parseInt(Splitter.lPanelMaxWidth) ? Splitter.lPanelMaxWidth : (w < parseInt(Splitter.lPanelMinWidth) ?
Splitter.lPanelMinWidth : w));
        w = _width;
}
Splitter.lPanel.style.width = w;
    }
};
</script>
</head>
<body onload="Splitter.init({id: 'splitter_Container', isWidthLimit: true});">
    <div id="splitter_container">
            <div id="splitter_left_panel">
                <iframe frameborder="0" height="100%" id="" width="100%" src="http://www.jb51.NET"></iframe>
            </div>
            <div id="splitter_bar"></div>
            <div id="splitter_right_panel">
                    在此處右鍵察看源代碼并把其中的js保存為splitter.js<br>
                    splitter.js使用方法:<br>
                    頁(yè)面上需要有一個(gè)div作為容器(id=splitter_container): 可拖動(dòng)效果就在這個(gè)容器里面進(jìn)行<br>
                    容器里面需要有3個(gè)div,分別代表左欄(id=splitter_left_panel),分割線(id=splitter_bar), 右欄(id=splitter_right_panel)<br>
                    這4個(gè)div需要用css修飾一下<br>
                    <code>
#splitter_container{
width: 100%;
height: 100%;
border: solid #eee 1px;
margin: 0px;
padding: 0px;
overflow: hidden;
}<br>
#splitter_left_panel{
width: 300px;
height: 100%;
float: left;
border: solid blue 0px;
}<br>
#splitter_bar{
width: 8px;
height: 100%;
float: left;
background-color: #ccc;
cursor: col-resize;
}<br>
#splitter_right_panel{
height: 100%;
padding-top: 10px;
}
</code>
<br><br>
給body加上onload事件處理函數(shù),以觸發(fā)splitter: <br>
onload="Splitter.init({id: 'splitter_Container', isWidthLimit: true});" <br>
Splitter的init方法傳入一個(gè)json對(duì)象作為配置參數(shù),其中容器id是必需的.<br>
還可以配置更多的參數(shù), 比如:<br>
isWidthLimit: 可選值true, false, 設(shè)置左面板是否限制寬度;<br>
lPanelMaxWidth: 左面板最大寬度,比如: 500px;<br>
lPanelMinWidth: 左面板最小寬度,比如: 100px;<br>
barActiveColor: 分割線拖動(dòng)的時(shí)候的顏色: 比如'red', '#0080ff';<br>
更多web開(kāi)發(fā)相關(guān)的內(nèi)容就在<a href='http://blog.csdn.NET/sunxing007'>blog.csdn.NET/sunxing007</a>    
            </div>
    </div>
</body>
</html>

JavaScript技術(shù)js 分欄效果實(shí)現(xiàn)代碼,轉(zhuǎn)載需保留來(lái)源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 欧美日韩加勒比一区二区三区 | 女女同性一区二区三区四区 | 中文字幕一区二区日产乱码 | 午夜激情小视频 | 国产成人乱码一区二区三区 | 久久精品国产99精品国产2021 | xxxxx在线 | 久久99精品久久久久久秒播 | 色综合久久夜色精品国产 | 成年人三级网站 | 国产精品亚洲一区二区三区正片 | 国产精品自产拍2021在线观看 | 大象蕉国产情侣 | 国产成人乱码一区二区三区 | 久久宗合色| 999无色码中文字幕 999影院成 人在线影院 | 色婷婷色丁香 | 亚洲欧洲日韩国产一区二区三区 | 久久精品乱子伦免费 | 一区二区在线视频观看 | 福利国产视频 | 亚洲精品网站在线 | 亚洲第一影院 | 久久久久久网站 | r18在线观看 | 日韩亚洲欧美综合一区二区三区 | 丁香婷婷成人 | 国产成人午夜精品5599 | 老湿司午夜爽爽影院榴莲视频 | 欧美亚洲激情 | 黄色免费网站在线观看 | 97一区二区三区 | 综合网在线观看 | 国产小视频在线 | 午夜免费观看_视频在线观看 | 国产成人 免费观看 | 欧美日本在线一区二区三区 | 国产成人久久精品麻豆二区 | 福利视频一区青娱 | 亚洲精品伊人 | 91麻豆精品国产91久久久久 |