单纯的手写滚动条dataTables表格插件下的滚动条
HTML部分代码 js部分代码
单纯的手写滚动条
这里调试过,没问题,可以直接复制了浏览器调试查看效果 大致思路:设置包裹内容div的容器div的overflow-y为hidden;调整内容div的top来滚动显示内容div的不同位置内容。检测鼠标滚动事件,设置容器div的max-height来设定每次最多显示多少px的内容,设置每次滚动滚多少px,也可通过拖动手写滚动条来快速访问; 手写的滚动条是容器div的第一个子div,贴容器div最右边,包括滚动条和内部滚轮,平时不显示,滚动或者鼠标移上去才显示,显示后又渐渐消失,保证不影响视觉效果。 滚动时,当鼠标在内容div区域时,如果可以滚动,优先滚动内容div,滚动到底或顶后再滚动外部页面。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Scrollbar
</title>
<script src="http://cdn.bootcss.com/jquery/3.2.1/jquery.js"></script>
</head>
<body>
<div id="wrapper" style="overflow-y: hidden;max-height: 500px;position: relative;border: 1px solid black;">
<div id="scrollbar" style="box-sizing:border-box;position:absolute;right:0;height:100%;z-index:100;opacity:0;padding:4px;width: 18px;">
<div id="scrollbar_roller" style="position:relative;top: 0px;width:100%;background-color:lightgray;border-radius:5px;"></div>
</div>
<div id="content" style="width:100%;height: 2000px;">
</div>
</div>
<script>
var visibleHeight = $('#wrapper').height();
var maxVisibleHeight = 500;
var rollHeight = 200;
var topHeight = 0;
var elseHeight = 0;
var upScrollFunc = function (e) {
visibleHeight = $('#wrapper').height();
if (visibleHeight == maxVisibleHeight) {
if ($('#content').height() > visibleHeight) {
$('#scrollbar_roller').css('height', Math.round($('#scrollbar').height() * visibleHeight / $('#content').height()) + 'px');
if (topHeight == 0) {
$('#content').css({'position': 'relative', 'top': '0px'});
elseHeight = $('#content').height() - visibleHeight;
$('#scrollbar').stop().animate({opacity: "1"}, 'fast', function () {
$('#scrollbar').stop().animate({opacity: "0"}, 'slow');
});
$('#scrollbar_roller').animate({'top': '0px'}, 1);
} else if (topHeight > rollHeight) {
e.preventDefault();
topHeight -= rollHeight;
$('#content').css({'position': 'relative', 'top': '-' + topHeight + 'px'});
elseHeight += rollHeight;
$('#scrollbar').stop().animate({opacity: "1"}, 'fast', function () {
$('#scrollbar').stop().animate({opacity: "0"}, 'slow');
});
$('#scrollbar_roller').animate({'top': Math.round($('#scrollbar').height() * topHeight / $('#content').height()) + 'px'}, 1);
} else if (topHeight <= rollHeight) {
e.preventDefault();
$('#content').css({'position': 'relative', 'top': '0px'});
topHeight = 0;
elseHeight = $('#content').height() - visibleHeight;
$('#scrollbar').stop().animate({opacity: "1"}, 'fast', function () {
$('#scrollbar').stop().animate({opacity: "0"}, 'slow');
});
$('#scrollbar_roller').animate({'top': '0px'}, 1);
}
}
} else {
$('#scrollbar').css('height', '0px');
$('#scrollbar_roller').css({'height': '0px', 'top': '0px'});
}
}
var downScrollFunc = function (e) {
visibleHeight = $('#wrapper').height();
if (visibleHeight == maxVisibleHeight) {
if ($('#content').height() > visibleHeight) {
$('#scrollbar_roller').css('height', Math.round($('#scrollbar').height() * visibleHeight / $('#content').height()) + 'px');
if (elseHeight == 0 && topHeight == 0) {
elseHeight = $('#content').height() - visibleHeight;
}
if (elseHeight == 0) {
topHeight = $('#content').height() - visibleHeight;
$('#content').css({'position': 'relative', 'top': '-' + topHeight + 'px'});
$('#scrollbar').stop().animate({opacity: "1"}, 'fast', function () {
$('#scrollbar').stop().animate({opacity: "0"}, 'slow');
});
} else if (elseHeight > rollHeight) {
e.preventDefault();
topHeight += rollHeight;
$('#content').css({'position': 'relative', 'top': '-' + topHeight + 'px'});
elseHeight -= rollHeight;
$('#scrollbar').stop().animate({opacity: "1"}, 'fast', function () {
$('#scrollbar').stop().animate({opacity: "0"}, 'slow');
});
$('#scrollbar_roller').animate({'top': Math.round((topHeight / $('#content').height()) * $('#scrollbar').height()) + 'px'}, 1);
} else if (elseHeight <= rollHeight) {
e.preventDefault();
elseHeight = 0;
topHeight = $('#content').height() - visibleHeight;
$('#content').css({'position': 'relative', 'top': '-' + topHeight + 'px'});
$('#scrollbar').stop().animate({opacity: "1"}, 'fast', function () {
$('#scrollbar').stop().animate({opacity: "0"}, 'slow');
});
$('#scrollbar_roller').animate({'top': $('#scrollbar').height() - $('#scrollbar_roller').height() + 'px'}, 1);
}
}
} else {
$('#scrollbar').css('height', '0px');
$('#scrollbar_roller').css({'height': '0px', 'top': '0px'});
}
}
var scrollFunc = function (e) {
e = e || window.event;
if (e.wheelDelta) {
if (e.wheelDelta > 0) {
upScrollFunc(e);
}
if (e.wheelDelta < 0) {
downScrollFunc(e);
}
} else if (e.detail) {
if (e.detail< 0) {
upScrollFunc(e);
}
if (e.detail> 0) {
downScrollFunc(e);
}
}
}
if ($('#content')[0].addEventListener) {
$('#content')[0].addEventListener('mousewheel', scrollFunc, false);
$('#content')[0].addEventListener('DOMMouseScroll', scrollFunc, false);
}
(function($, h, c) {
var a = $([]), e = $.resize = $.extend($.resize, {}), i, k = "setTimeout", j = "resize", d = j
+ "-special-event", b = "delay", f = "throttleWindow";
e[b] = 350;
e[f] = true;
$.event.special[j] = {
setup : function() {
if (!e[f] && this[k]) {
return false
}
var l = $(this);
a = a.add(l);
$.data(this, d, {
w : l.width(),
h : l.height()
});
if (a.length === 1) {
g()
}
},
teardown : function() {
if (!e[f] && this[k]) {
return false
}
var l = $(this);
a = a.not(l);
l.removeData(d);
if (!a.length) {
clearTimeout(i)
}
},
add : function(l) {
if (!e[f] && this[k]) {
return false
}
var n;
function m(s, o, p) {
var q = $(this), r = $.data(this, d);
r.w = o !== c ? o : q.width();
r.h = p !== c ? p : q.height();
n.apply(this, arguments)
}
if ($.isFunction(l)) {
n = l;
return m
} else {
n = l.handler;
l.handler = m
}
}
};
function g() {
i = h[k](function() {
a.each(function() {
var n = $(this), m = n.width(), l = n.height(), o = $
.data(this, d);
if (m !== o.w || l !== o.h) {
n.trigger(j, [ o.w = m, o.h = l ])
}
});
g()
}, e[b])
}
})(jQuery, this);
$('#content').resize(function(){
alert('test');
if(visibleHeight == maxVisibleHeight){
if($('#content').height() !== $('#wrapper').data('#content_height')){
topHeight *= $('#content').height()/$('#wrapper').data('content_height');
$('#scrollbar_roller').css('height', Math.round($('#scrollbar').height()*visibleHeight/$('#content').height())+'px');
}
}else{
topHeight=0;
$('#scrollbar').css('height','0px');
$('#scrollbar_roller').css({'height':'0px','top':'0px'});
}
if (topHeight + visibleHeight > $('#content').height()) {
topHeight = $('#content').height() - visibleHeight;
}
elseHeight = $('#content').height() - topHeight - visibleHeight;
$('#content').css({'position': 'relative', 'top': '-' + topHeight + 'px'});
$('#wrapper').data('content_height',$('#content').height());
});
var topPlace=0;
var topPointY=0;
$('#scrollbar_roller').mouseover(function () {
$('#scrollbar').stop().animate({opacity:"1"}, 'fast');
});
$('#scrollbar_roller').mouseleave(function () {
$('#scrollbar').stop().animate({opacity:"0"},"slow");
});
$('#scrollbar_roller').mousedown(function (event) {
topPlace=$('#scrollbar_roller').css('top');
topPlace=parseInt(topPlace.substr(0, topPlace.length-2));
topPointY=event.pageY;
return false;
});
$('#scrollbar_roller').mousemove(function (event) {
event = event || window.event;
if(event.buttons == 1){
var newPlace=topPlace+event.pageY-topPointY;
var ceilLimit=$('#scrollbar').height()-$('#scrollbar_roller').height();
if(newPlace>0 && newPlace<ceilLimit){
$('#scrollbar_roller').css('top',newPlace+'px');
topHeight=newPlace/$('#scrollbar').height()*$('#content').height();
elseHeight=$('#content').height()-topHeight-maxVisibleHeight;
$('#content').css({'position':'relative','top':'-'+topHeight+'px'});
}else if(newPlace<=0){
$('#scrollbar_roller').css('top','0px');
topHeight=0;
elseHeight=$('#content').height()-maxVisibleHeight;
$('#content').css({'position':'relative','top':'0px'});
}else if(newPlace>=ceilLimit){
$('#scrollbar_roller').css('top', ceilLimit+'px');
topHeight=$('#content').height()-maxVisibleHeight;
elseHeight=0;
$('#content').css({'position':'relative','top':'-'+($('#content').height()-maxVisibleHeight)+'px'});
}
}
});
$('#wrapper').mousemove(function (event) {
event = event || window.event;
if(event.buttons==1 && topPointY){
$('#scrollbar').stop().css({'opacity':'1'});
var newPlace=topPlace+event.pageY-topPointY;
var ceilLimit=$('#scrollbar').height()-$('#scrollbar_roller').height();
if(newPlace>0 && newPlace<ceilLimit){
$('#scrollbar_roller').css('top',newPlace+'px');
topHeight=newPlace/$('#scrollbar').height()*$('#content').height();
elseHeight=$('#content').height()-topHeight-maxVisibleHeight;
$('#content').css({'position':'relative','top':'-'+topHeight+'px'});
}else if(newPlace<=0){
$('#scrollbar_roller').css('top','0px');
topHeight=0;
elseHeight=$('#content').height()-maxVisibleHeight;
$('#content').css({'position':'relative','top':'0px'});
}else if(newPlace>=ceilLimit){
$('#scrollbar_roller').css('top', ceilLimit+'px');
topHeight=$('#content').height()-maxVisibleHeight;
elseHeight=0;
$('#content').css({'position':'relative','top':'-'+($('#content').height()-maxVisibleHeight)+'px'});
}
}
});
$('body').mouseup(function () {
topPlace=0;
topPointY=0;
$('#scrollbar').stop().animate({opacity:"0"},"slow");
});
$('body').mouseleave(function () {
$('#scrollbar').stop().animate({opacity:"0"},"slow");
});
</script>
</body>
</html>
dataTables表格插件下的滚动条
之所以要弄这个手写滚动条,是因为组长觉得,外面页面一个滚动条,里面表格再一个滚动条,不好看。不加滚动条全部显示出来的话,点击分页跳转又不方便,反正没事儿我就试着自己写了个。可惜组长最后还是觉得一进来就有水平滚动条不好,不能一眼看到全部数据,哎,那么多列,dataTables缩小页面的时候直接就把多的列hide了,把水平滚动条弄出来方便响应式不好么?不能理解设计思路,现在把表头都压换行了,特丑。去掉了框架有关的类和其他的,想用到自己的项目中的话,具体代码需要适当改动这个插件也挺坑的,哎,具体看注释吧,以后有时间再写详细点
HTML部分代码:
<header style="position: relative;">
</header>
<div style="position:relative;">
<div id="scrollbar" style="box-sizing:content-box;position:absolute;right:0;z-index:100;opacity:0;padding:4px;width: 10px;">
<div style="position:relative;top: 0px;width:100%;background-color:lightgray;border-radius:5px;">
</div>
</div>
<div>
<table id="example" class="table table-striped table-bordered" width="100%"></table>
</div>
</div>
<footer style="position:absolute;top:33px;width:100%;height:160px;line-height:100px;background-color:white;text-align: center; font-size: x-large; padding: 30px 0px;z-index:100;">
<span><i class="fa fa-refresh fa-spin"></i> 加载中
</span>
</footer>
js部分代码:
var dataTablesObj =
null;
function getColumns(type) {
var columns = [
{title:
"xxx", data:
"xxx",width:
60},
{title:
"xxx", data:
"xxx",width:
60},
{title:
"xxx", data:
"xxx",width:
450},
{title:
"xxx", data:
"xxx",width:
150},
{title:
"xxx", data:
"xxx",width:
80}
];
return columns;
}
var pagefunction =
function () {
$(
'[role="content"]').hide();
$(
'footer').css(
'z-index',
'100');
function createDataTables(objid, url, type) {
var lang = {
xxx:
'xxx...'
};
if (dataTablesObj) {
dataTablesObj.destroy();
}
dataTables = $(
'#' + objid).DataTable({
language: lang,
autoWidth:
false,
stripeClasses: [
"odd",
"even"],
processing:
true,
serverSide:
true,
orderMulti:
false,
order: [],
deferRender:
true,
lengthMenu: [
[
10,
25,
50,
100,
300],
[
10,
25,
50,
100,
300]
],
renderer:
"bootstrap",
pagingType:
"simple_numbers",
scrollX:
true,
pageLength:
10,
columns: getColumns(type),
sDom:
"<'dt-toolbar'<'col-xs-12 col-sm-8 hidden-xs'><'col-xs-12 col-sm-4 text-right hidden-xs'i><'toolbar'>>" +
"t" +
"<'dt-toolbar-footer'<'col-xs-12 col-sm-2 hidden-xs'l><'col-xs-12 col-sm-10'p>>",
ajax:
function(data, callback, settings) {}
});
function getScrollWidth() {
var noScroll, scroll, Div = document.createElement(
"div");
Div.style.cssText =
"position:absolute; top:-1000px; width:100px; height:100px; overflow:hidden;";
noScroll = document.body.appendChild(Div).clientWidth;
Div.style.overflowY =
"scroll";
scroll = Div.clientWidth;
document.body.removeChild(Div);
return noScroll-scroll;
}
var tableVisibleHeight=$(
'.dataTables_scrollBody').height();
var maxTableVisibleHeight=
500;
var rollHeight=
200;
var topHeight=
0;
var elseHeight=
0;
var upScrollFunc=
function (e) {
if($(
'.dataTables_scrollHead table').width()<=$($(
'header')[
1]).width()){
maxTableVisibleHeight=
500;
tableVisibleHeight=$(
'.dataTables_scrollBody').height();
if(tableVisibleHeight==maxTableVisibleHeight){
if($(
'#example').height()>tableVisibleHeight){
$(
'#scrollbar').css(
'height',tableVisibleHeight-
8+
'px');
$(
'#scrollbar').children().css(
'height',
Math.round($(
'#scrollbar').height()*tableVisibleHeight/$(
'#example').height())+
'px');
if(topHeight==
0){
$(
'#example').css({
'position':
'relative',
'top':
'0px'});
elseHeight=$(
'#example').height()-tableVisibleHeight;
console.log(elseHeight);
$(
'#scrollbar').stop().animate({opacity:
"1"},
'fast',
function(){
$(
'#scrollbar').stop().animate({opacity:
"0"},
'slow');
});
$(
'#scrollbar').children().animate({
'top':
'0px'},
1);
}
else if(topHeight>rollHeight){
e.preventDefault();
topHeight-=rollHeight;
$(
'#example').css({
'position':
'relative',
'top':
'-'+topHeight+
'px'});
elseHeight+=rollHeight;
$(
'#scrollbar').stop().animate({opacity:
"1"},
'fast',
function(){
$(
'#scrollbar').stop().animate({opacity:
"0"},
'slow');
});
$(
'#scrollbar').children().animate({
'top':
Math.round($(
'#scrollbar').height()*topHeight/$(
'#example').height())+
'px'},
1);
}
else if(topHeight<=rollHeight){
e.preventDefault();
elseHeight=$(
'#example').height()-tableVisibleHeight;
$(
'#example').css({
'position':
'relative',
'top':
'0px'});
topHeight=
0;
$(
'#scrollbar').stop().animate({opacity:
"1"},
'fast',
function(){
$(
'#scrollbar').stop().animate({opacity:
"0"},
'slow');
});
$(
'#scrollbar').children().animate({
'top':
'0px'},
1);
}
}
}
else{
$(
'#scrollbar').css(
'height',
'0px');
$(
'#scrollbar').children().css({
'height':
'0px',
'top':
'0px'});
}
}
else if($(
'.dataTables_scrollHead table').width()>$($(
'header')[
1]).width()){
maxTableVisibleHeight=
500-getScrollWidth();
tableVisibleHeight=$(
'.dataTables_scrollBody').height()-getScrollWidth();
if(tableVisibleHeight==maxTableVisibleHeight) {
if($(
'#example').height()>tableVisibleHeight){
$(
'#scrollbar').css(
'height',tableVisibleHeight-
8+
'px');
$(
'#scrollbar').children().css(
'height',
Math.round($(
'#scrollbar').height()*tableVisibleHeight/$(
'#example').height())+
'px');
if(topHeight==
0){
$(
'#example').css({
'position':
'relative',
'top':
'0px'});
elseHeight=$(
'#example').height()-tableVisibleHeight;
console.log(elseHeight);
$(
'#scrollbar').stop().animate({opacity:
"1"},
'fast',
function(){
$(
'#scrollbar').stop().animate({opacity:
"0"},
'slow');
});
$(
'#scrollbar').children().animate({
'top':
'0px'},
1);
}
else if(topHeight>rollHeight){
e.preventDefault();
topHeight-=rollHeight;
$(
'#example').css({
'position':
'relative',
'top':
'-'+topHeight+
'px'});
elseHeight+=rollHeight;
$(
'#scrollbar').stop().animate({opacity:
"1"},
'fast',
function(){
$(
'#scrollbar').stop().animate({opacity:
"0"},
'slow');
});
$(
'#scrollbar').children().animate({
'top':
Math.round((topHeight/$(
'#example').height())*$(
'#scrollbar').height())+
'px'},
1);
}
else if(topHeight<=rollHeight){
e.preventDefault();
elseHeight=$(
'#example').height()-tableVisibleHeight;
$(
'#example').css({
'position':
'relative',
'top':
'0px'});
topHeight=
0;
$(
'#scrollbar').stop().animate({opacity:
"1"},
'fast',
function(){
$(
'#scrollbar').stop().animate({opacity:
"0"},
'slow');
});
$(
'#scrollbar').children().animate({
'top':
'0px'},
1);
}
}
}
else{
$(
'#scrollbar').css(
'height',
'0px');
$(
'#scrollbar').children().css({
'height':
'0px',
'top':
'0px'});
}
}
}
var downScrollFunc=
function (e) {
if($(
'.dataTables_scrollHead table').width()<=$($(
'header')[
1]).width()){
maxTableVisibleHeight=
500;
tableVisibleHeight=$(
'.dataTables_scrollBody').height();
if(tableVisibleHeight==maxTableVisibleHeight){
if($(
'#example').height()>tableVisibleHeight){
$(
'#scrollbar').css(
'height',tableVisibleHeight -
8 +
'px');
if($(
'#scrollbar').children().height()!==
Math.round($(
'#scrollbar').height()*tableVisibleHeight/$(
'#example').height())){
$(
'#scrollbar').children().css(
'height',
Math.round($(
'#scrollbar').height()*tableVisibleHeight/$(
'#example').height())+
'px');
}
if(elseHeight==
0 && topHeight ==
0){
elseHeight=$(
'#example').height()-tableVisibleHeight;
}
if (elseHeight ==
0){
topHeight=$(
'#example').height()-tableVisibleHeight;
$(
'#example').css({
'position':
'relative',
'top':
'-'+topHeight+
'px'});
$(
'#scrollbar').stop().animate({opacity:
"1"},
'fast',
function(){
$(
'#scrollbar').stop().animate({opacity:
"0"},
'slow');
});
}
else if(elseHeight>rollHeight){
e.preventDefault();
topHeight+=rollHeight;
$(
'#example').css({
'position':
'relative',
'top':
'-'+topHeight+
'px'});
elseHeight-=rollHeight;
$(
'#scrollbar').stop().animate({opacity:
"1"},
'fast',
function(){
$(
'#scrollbar').stop().animate({opacity:
"0"},
'slow');
});
$(
'#scrollbar').children().animate({
'top':
Math.round((topHeight/$(
'#example').height())*$(
'#scrollbar').height())+
'px'},
1);
}
else if(elseHeight<=rollHeight){
e.preventDefault();
elseHeight=
0;
topHeight=$(
'#example').height()-tableVisibleHeight;
$(
'#example').css({
'position':
'relative',
'top':
'-'+topHeight+
'px'});
$(
'#scrollbar').stop().animate({opacity:
"1"},
'fast',
function(){
$(
'#scrollbar').stop().animate({opacity:
"0"},
'slow');
});
$(
'#scrollbar').children().animate({
'top':$(
'#scrollbar').height()-$(
'#scrollbar').children().height()+
'px'},
1);
}
}
}
else{
$(
'#scrollbar').css(
'height',
'0px');
$(
'#scrollbar').children().css({
'height':
'0px',
'top':
'0px'});
}
}
else if($(
'.dataTables_scrollHead table').width()>$($(
'header')[
1]).width()){
maxTableVisibleHeight=
500-getScrollWidth();
tableVisibleHeight=$(
'.dataTables_scrollBody').height()-getScrollWidth();
if(tableVisibleHeight==maxTableVisibleHeight) {
if ($(
'#example').height() > tableVisibleHeight) {
$(
'#scrollbar').css(
'height', tableVisibleHeight-
8 +
'px');
$(
'#scrollbar').children().css(
'height',
Math.round($(
'#scrollbar').height() * tableVisibleHeight / $(
'#example').height()) +
'px');
if (elseHeight ==
0 && topHeight ==
0) {
elseHeight = $(
'#example').height() - tableVisibleHeight;
}
if (elseHeight ==
0) {
topHeight = $(
'#example').height() - tableVisibleHeight;
$(
'#example').css({
'position':
'relative',
'top':
'-' + topHeight +
'px'});
$(
'#scrollbar').stop().animate({opacity:
"1"},
'fast',
function(){
$(
'#scrollbar').stop().animate({opacity:
"0"},
'slow');
});
}
else if (elseHeight > rollHeight) {
e.preventDefault();
topHeight += rollHeight;
$(
'#example').css({
'position':
'relative',
'top':
'-' + topHeight +
'px'});
elseHeight -= rollHeight;
$(
'#scrollbar').stop().animate({opacity:
"1"},
function () {
$(
'#scrollbar').stop().animate({opacity:
"0"},
'slow');
});
$(
'#scrollbar').children().animate({
'top':
Math.round((topHeight / $(
'#example').height()) * $(
'#scrollbar').height()) +
'px'},
1);
}
else if (elseHeight <= rollHeight) {
e.preventDefault();
elseHeight =
0;
topHeight = $(
'#example').height() - tableVisibleHeight;
$(
'#example').css({
'position':
'relative',
'top':
'-' + topHeight +
'px'});
$(
'#scrollbar').stop().animate({opacity:
"1"},
function () {
$(
'#scrollbar').stop().animate({opacity:
"0"},
'slow');
});
$(
'#scrollbar').children().animate({
'top': $(
'#scrollbar').height() - $(
'#scrollbar').children().height() +
'px'},
1);
}
}
}
else{
$(
'#scrollbar').css(
'height',
'0px');
$(
'#scrollbar').children().css({
'height':
'0px',
'top':
'0px'});
}
}
}
var scrollFunc =
function (e) {
e = e || window.event;
if (e.wheelDelta) {
if (e.wheelDelta >
0) {
upScrollFunc(e);
}
if (e.wheelDelta <
0) {
downScrollFunc(e);
}
}
else if (e.detail) {
if (e.detail<
0) {
upScrollFunc(e);
}
if (e.detail>
0) {
downScrollFunc(e);
}
}
}
if ($(
'#example')[
0].addEventListener) {
$(
'#example')[
0].addEventListener(
'mousewheel', scrollFunc,
false);
$(
'#example')[
0].addEventListener(
'DOMMouseScroll', scrollFunc,
false);
}
$(
'#example').resize(
function(){
setTimeout(
function () {
$(
'#scrollbar').css(
'top',$(
'.dt-toolbar').outerHeight()+$(
'.dataTables_scrollHead').outerHeight()+
'px');
},
10);
if($(
'.dataTables_scrollHead table').width()>$($(
'header')[
1]).width()) {
maxTableVisibleHeight =
500 - getScrollWidth();
tableVisibleHeight = $(
'.dataTables_scrollBody').height() - getScrollWidth();
}
else{
maxTableVisibleHeight =
500;
tableVisibleHeight = $(
'.dataTables_scrollBody').height();
}
if(tableVisibleHeight == maxTableVisibleHeight){
if($(
'#example').height() !== $(
'.dataTables_scrollBody').data(
'#example_height')){
topHeight *= $(
'#example').height()/$(
'.dataTables_scrollBody').data(
'#example_height');
$(
'#scrollbar').css(
'height',tableVisibleHeight-
8+
'px');
$(
'#scrollbar').children().css(
'height',
Math.round($(
'#scrollbar').height()*tableVisibleHeight/$(
'#example').height())+
'px');
}
}
else{
topHeight=
0;
$(
'#scrollbar').css(
'height',
'0px');
$(
'#scrollbar').children().css({
'height':
'0px',
'top':
'0px'});
}
if (topHeight + tableVisibleHeight > $(
'#example').height()) {
topHeight = $(
'#example').height() - tableVisibleHeight;
}
elseHeight = $(
'#example').height() - topHeight - tableVisibleHeight;
$(
'#example').css({
'position':
'relative',
'top':
'-' + topHeight +
'px'});
$(
'.dataTables_scrollBody').data(
'#example_height',$(
'#example').height());
});
var topPlace=
0;
var topPointY=
0;
$(
'#scrollbar').children().mouseover(
function () {
$(
'#scrollbar').stop().animate({opacity:
"1"},
'fast');
});
$(
'#scrollbar').children().mouseleave(
function () {
$(
'#scrollbar').stop().animate({opacity:
"0"},
"slow");
});
$(
'#scrollbar').children().mousedown(
function (event) {
topPlace=$(
'#scrollbar').children().css(
'top');
topPlace=
parseInt(topPlace.substr(
0, topPlace.length-
2));
topPointY=event.pageY;
return false;
});
$(
'#scrollbar').children().mousemove(
function (event) {
event = event || window.event;
if(event.buttons ==
1){
var newPlace=topPlace+event.pageY-topPointY;
var ceilLimit=$(
'#scrollbar').height()-$(
'#scrollbar').children().height();
if(newPlace>
0 && newPlace<ceilLimit){
$(
'#scrollbar').children().css(
'top',newPlace+
'px');
topHeight=newPlace/$(
'#scrollbar').height()*$(
'#example').height();
elseHeight=$(
'#example').height()-topHeight-maxTableVisibleHeight;
$(
'#example').css({
'position':
'relative',
'top':
'-'+topHeight+
'px'});
}
else if(newPlace<=
0){
$(
'#scrollbar').children().css(
'top',
'0px');
topHeight=
0;
elseHeight=$(
'#example').height()-maxTableVisibleHeight;
$(
'#example').css({
'position':
'relative',
'top':
'0px'});
}
else if(newPlace>=ceilLimit){
$(
'#scrollbar').children().css(
'top', ceilLimit+
'px');
topHeight=$(
'#example').height()-maxTableVisibleHeight;
elseHeight=
0;
$(
'#example').css({
'position':
'relative',
'top':
'-'+($(
'#example').height()-maxTableVisibleHeight)+
'px'});
}
}
});
$(
'.dataTables_scrollBody').mousemove(
function (event) {
event = event || window.event;
if(event.buttons==
1 && topPointY){
$(
'#scrollbar').stop().css({
'opacity':
'1'});
var newPlace=topPlace+event.pageY-topPointY;
var ceilLimit=$(
'#scrollbar').height()-$(
'#scrollbar').children().height();
if(newPlace>
0 && newPlace<ceilLimit){
$(
'#scrollbar').children().css(
'top',newPlace+
'px');
topHeight=newPlace/$(
'#scrollbar').height()*$(
'#example').height();
elseHeight=$(
'#example').height()-topHeight-maxTableVisibleHeight;
$(
'#example').css({
'position':
'relative',
'top':
'-'+topHeight+
'px'});
}
else if(newPlace<=
0){
$(
'#scrollbar').children().css(
'top',
'0px');
topHeight=
0;
elseHeight=$(
'#example').height()-maxTableVisibleHeight;
$(
'#example').css({
'position':
'relative',
'top':
'0px'});
}
else if(newPlace>=ceilLimit){
$(
'#scrollbar').children().css(
'top', ceilLimit+
'px');
topHeight=$(
'#example').height()-maxTableVisibleHeight;
elseHeight=
0;
$(
'#example').css({
'position':
'relative',
'top':
'-'+($(
'#example').height()-maxTableVisibleHeight)+
'px'});
}
}
});
$(
'body').mouseup(
function () {
topPlace=
0;
topPointY=
0;
$(
'#scrollbar').stop().animate({opacity:
"0"},
"slow");
});
$(
'body').mouseleave(
function () {
$(
'#scrollbar').stop().animate({opacity:
"0"},
"slow");
});
dataTables.on(
'draw.dt',
function () {
$(
'.dataTables_scrollBody').css({
'max-height':
'500px',
'overflow-y':
'hidden'
});
$(
'#scrollbar').css(
'top',$(
'.dt-toolbar').outerHeight()+$(
'th').outerHeight()+
'px');
$(
'td').css({
'word-break':
'break-all',
'word-wrap':
'break-word'});
if ($(
'td').length ==
1) {
$(
'td').attr(
'colspan', $(
'.dataTables_scrollHead table').find(
'th').length);
}
var len=[
'xxx',
'xxx',
'xxx',
'...'];
var table_min_length=
0;
for(i=
0;i<len.length;i++){
table_min_length+=len[i]+
27;
}
table_min_length+=len.length-
1;
function changeTableWidth() {
var headerWidth = $($(
'header')[
1]).width();
if (headerWidth <= table_min_length) {
$(
'.dataTables_scrollHead table').width(table_min_length);
$(
'.dataTables_scrollBody table').width(table_min_length);
}
else {
$(
'.dataTables_scrollHead table').width(headerWidth);
$(
'.dataTables_scrollBody table').width(headerWidth);
}
if ($(
'td').length >
1) {
if ($($(
'td')[
0]).width() -
7 !== $($(
'th')[
0]).width() || $($(
'td')[
0]).width() <
67) {
var diff = $($(
'td')[
0]).width();
var bodyArr = $(
'.dataTables_scrollBody table').find(
'tr');
for (
var i =
1; i < bodyArr.length; i++) {
for (
var j =
0; j < len.length; j++) {
$($(bodyArr[i]).find(
'td')[j]).css(
'width', len[j] +
7);
}
}
if ($($(
'td')[
0]).width() <
67 || $($(
'td')[
0]).width() <= diff) {
var len2 = [];
for (
var i =
0; i < len.length; i++) {
len2.push($($(
'td')[i]).width());
}
var headArr = $(
'.dataTables_scrollHead table').find(
'th');
for (
var i =
0; i < headArr.length; i++) {
$(headArr[i]).css(
'width', len2[i] -
7);
}
}
}
}
}
changeTableWidth();
$(
'footer').css(
'z-index',
'-1');
$(
'[role="content"]').show();
$(
'.widget-body').resize(changeTableWidth);
var headArr = $(
'.dataTables_scrollHead table').find(
'th');
for (
var i =
0; i < headArr.length; i++) {
$(headArr[i]).css(
'width', len[i]);
}
var bodyArr = $(
'.dataTables_scrollBody table').find(
'tr');
if ($(
'td').length >
1) {
for (
var i =
1; i < bodyArr.length; i++) {
for (
var j =
0; j < len.length; j++) {
$($(bodyArr[i]).find(
'td')[j]).css(
'width', len[j] +
7);
}
}
}
else if ($(
'td').length ==
1) {
$(
'td').attr(
'colspan', len.length);
}
topHeight=
0;
elseHeight=
0;
$(
'#scrollbar').children().css(
'top',
'0px');
$(
'#example').css({
'position':
'relative',
'top':
'0px'});
if($(
'.dataTables_scrollHead table').width()<=$($(
'header')[
1]).width()) {
maxTableVisibleHeight =
500;
tableVisibleHeight = $(
'.dataTables_scrollBody').height();
}
else{
maxTableVisibleHeight =
500-getScrollWidth();
tableVisibleHeight = $(
'.dataTables_scrollBody').height()-getScrollWidth();
}
if(tableVisibleHeight<maxTableVisibleHeight){
$(
'#scrollbar').css(
'height',
'0px');
$(
'#scrollbar').children().css({
'height':
'0px',
'top':
'0px'});
}
else{
$(
'#scrollbar').css(
'height',tableVisibleHeight -
8 +
'px');
$(
'#scrollbar').children().css(
'height',
Math.round($(
'#scrollbar').height()*tableVisibleHeight/$(
'#example').height())+
'px');
}
$(
'.dataTables_scrollBody').data(
'#example_height',$(
'#example').height());
});
return dataTables;
}
dataTablesObj = createDataTables(
'xxx',
'xxx',
'xxx');
};
loadScript(
"../static/framework/js/plugin/datatable-responsive/datatables.responsive.min.js", pagefunction);