Skip to content

Instantly share code, notes, and snippets.

@ginlime
Created October 30, 2015 02:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ginlime/87d0059c0740b43eb036 to your computer and use it in GitHub Desktop.
Save ginlime/87d0059c0740b43eb036 to your computer and use it in GitHub Desktop.
jQuery version of footerFixed.js
/*--------------------------------------------------------------------------*
*
* jQuery.footerFixed.js
*
* MIT-style license.
*
* ported by @ginlime
* https://gist.github.com/ginlime
*
* original written by:
* 2007 Kazuma Nishihata [to-R]
* http://blog.webcreativepark.net
*
*--------------------------------------------------------------------------*/
(function($){
var footerId = 'footer';
// 文字サイズ
var checkFontSize = function(func){
// 判定要素の追加
$('body').append($('<div></div>').attr('id','ff-node-temp').css({'position':'absolute','top':'0','visibility':'hidden'}).text('S'));
var defHeight = $('#ff-node-temp').prop('offsetHeight');
// 判定関数
var checkBoxSize = function(){
if(defHeight != $('#ff-node-temp').prop('offsetHeight')){
func();
defHeight = $('#ff-node-temp').prop('offsetHeight');
}
};
setInterval(checkBoxSize, 1000);
};
var footerFixed = function(){
// ドキュメントの高さ
var dh = $('body').prop('clientHeight');
// フッターのtopからの位置
$('#'+footerId).css('top','0');
var ft = $('#'+footerId).prop('offsetTop');
// フッターの高さ
var fh = $('#'+footerId).prop('offsetHeight');
// ウィンドウの高さ
var wh = $(window).prop('innerHeight');
if(ft+fh<wh){
$('#'+footerId).css({'position':'relative','top':(wh-fh-ft-1)+'px'});
}
};
$(window).on('load resize',function(e){footerFixed()});
$(window).on('load',function(e){checkFontSize(footerFixed)});
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment