Commit 39e7e271 by o.kimura

テーブルヘッダ固定調整中

parent b1ad492d
/*!
* jQuery FixedTableHeader plugin
*
* Copyright 2014 Hung Nguyen
*
* Date: Tue Nov 4 2014 07:00:00 GMT
*/
/*jslint browser: true, nomen: true, unparam: true, node: true*/
/*global $, jQuery*/
'use strict';
(function ($) {
$.fn.fixedTableHeader = function () {
return this.each(function (key, item) {
var $self = $(this),
$fixedHeader,
$originalHeader,
tableTopOffset,
tableBottomOffset,
headerHeight,
originalWidth = [];
$self.find('thead > tr > th').each(function (key, item) {
originalWidth.push($(item).outerWidth());
});
function init() {
var ua = navigator.userAgent;
if (ua.indexOf('iPhone') > 0 || ua.indexOf('Android') > 0 && ua.indexOf('Mobile') > 0) {
$originalHeader = $self.find('thead:first');
$fixedHeader = $originalHeader.clone();
$fixedHeader.css('position', 'fixed');
$fixedHeader.css('display', 'none');
$fixedHeader.css('height', $self.find('thead').outerHeight());
$fixedHeader.css('width', $self.find('thead').outerWidth());
$fixedHeader.css('top', 100);
$fixedHeader.css('left', $self.find('thead').offset().left);
$fixedHeader.css('margin-top', 0);
$fixedHeader.css('z-index', 1);
$originalHeader.after($fixedHeader);
} else {
$originalHeader = $self.find('thead:first');
$fixedHeader = $originalHeader.clone();
$fixedHeader.css('position', 'fixed');
$fixedHeader.css('display', 'none');
$fixedHeader.css('height', $self.find('thead').outerHeight());
$fixedHeader.css('width', $self.find('thead').outerWidth());
$fixedHeader.css('top', 50);
$fixedHeader.css('left', $self.find('thead').offset().left);
$fixedHeader.css('margin-top', 0);
$fixedHeader.css('z-index', 1);
$originalHeader.after($fixedHeader);
}
}
function left() {
return parseInt($self.offset().left, 10) - parseInt($(window).scrollLeft(), 10);
}
function onResize() {
$fixedHeader.css('left', left());
$fixedHeader.css('width', $self.find('thead').outerWidth());
$fixedHeader.find("th").each(function (index) {
originalWidth[index] = $originalHeader.find("th").eq(index).outerWidth();
$(this).css("min-width", $originalHeader.find("th").eq(index).outerWidth());
$(this).css("max-width", $originalHeader.find("th").eq(index).outerWidth());
});
}
function onScroll() {
tableTopOffset = $self.offset().top;
headerHeight = $fixedHeader.find('tr').height();
tableBottomOffset = tableTopOffset + $self.height() - headerHeight;
$fixedHeader.find('th').each(function (key, item) {
$(item).css('min-width', parseInt(originalWidth[key], 10));
$(item).css('max-width', parseInt(originalWidth[key], 10));
});
$fixedHeader.css('left', left());
if ($(window).scrollTop() > tableTopOffset && $(window).scrollTop() < tableBottomOffset) {
$fixedHeader.show();
} else {
$fixedHeader.hide();
}
}
init();
$(window).resize(onResize);
$(window).scroll(onScroll);
});
};
}(jQuery));
"use strict";!function(e){e.fn.fixedTableHeader=function(){return this.each(function(){function c(){var e=navigator.userAgent;e.indexOf("iPhone")>0||e.indexOf("Android")>0&&e.indexOf("Mobile")>0?(o=i.find("thead:first"),r=o.clone(),r.css("position","fixed"),r.css("display","none"),r.css("height",i.find("thead").outerHeight()),r.css("width",i.find("thead").outerWidth()),r.css("top",100),r.css("left",i.find("thead").offset().left),r.css("margin-top",0),r.css("z-index",1),o.after(r)):(o=i.find("thead:first"),r=o.clone(),r.css("position","fixed"),r.css("display","none"),r.css("height",i.find("thead").outerHeight()),r.css("width",i.find("thead").outerWidth()),r.css("top",50),r.css("left",i.find("thead").offset().left),r.css("margin-top",0),r.css("z-index",1),o.after(r))}function f(){return parseInt(i.offset().left,10)-parseInt(e(window).scrollLeft(),10)}function d(){r.css("left",f()),r.css("width",i.find("thead").outerWidth()),r.find("th").each(function(t){l[t]=o.find("th").eq(t).outerWidth(),e(this).css("min-width",o.find("th").eq(t).outerWidth()),e(this).css("max-width",o.find("th").eq(t).outerWidth())})}function p(){s=i.offset().top,u=r.find("tr").height(),a=s+i.height()-u,r.find("th").each(function(t,n){e(n).css("min-width",parseInt(l[t],10)),e(n).css("max-width",parseInt(l[t],10))}),r.css("left",f()),e(window).scrollTop()>s&&e(window).scrollTop()<a?r.show():r.hide()}var r,o,s,a,u,i=e(this),l=[];i.find("thead > tr > th").each(function(t,n){l.push(e(n).outerWidth())}),c(),e(window).resize(d),e(window).scroll(p)})}}(jQuery);
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment