
###目的
画面読み込み時と、'input[name=check]'
のクリック時に、#fotter
を画面下に固定したいです。
#fotte
高さをCSSで指定して、という方法でなくjavascriptでやってみたいと思います。
###試したコード
次のjavascriptを試しました。
読み込み時には下にいくものの、'input[name=check]'
をクリックしても下にいってくれません。
'input[name=check]'
をクリックすると画面から要素が消え、#fotte
がその分上に浮いてしまいます。そのときに次のjavascriptが作動してくれればいいのですが、なぜか浮いたままになってしまうのです。(しかし浮いたままのときにF12を押すとちゃっかり画面下にいきます。)
javascript
1(function($){ 2 function funcFooter(){ 3 4 var footerId = "footer"; 5 //メイン 6 function footerFixed(){ 7 //ドキュメントの高さ 8 var dh = document.getElementsByTagName("body")[0].clientHeight; 9 //フッターのtopからの位置 10 document.getElementById(footerId).style.top = "0px"; 11 var ft = document.getElementById(footerId).offsetTop; 12 //フッターの高さ 13 var fh = document.getElementById(footerId).offsetHeight; 14 //ウィンドウの高さ 15 if (window.innerHeight){ 16 var wh = window.innerHeight; 17 }else if(document.documentElement && document.documentElement.clientHeight != 0){ 18 var wh = document.documentElement.clientHeight; 19 } 20 if(ft+fh<wh){ 21 document.getElementById(footerId).style.position = "relative"; 22 document.getElementById(footerId).style.top = (wh-fh-ft-1)+"px"; 23 } 24 } 25 26 //文字サイズ 27 function checkFontSize(func){ 28 29 //判定要素の追加 30 var e = document.createElement("div"); 31 var s = document.createTextNode("S"); 32 e.appendChild(s); 33 e.style.visibility="hidden" 34 e.style.position="absolute" 35 e.style.top="0" 36 document.body.appendChild(e); 37 var defHeight = e.offsetHeight; 38 39 //判定関数 40 function checkBoxSize(){ 41 if(defHeight != e.offsetHeight){ 42 func(); 43 defHeight= e.offsetHeight; 44 } 45 } 46 setInterval(checkBoxSize,1000) 47 } 48 49 //イベントリスナー 50 function addEvent(elm,listener,fn){ 51 try{ 52 elm.addEventListener(listener,fn,false); 53 }catch(e){ 54 elm.attachEvent("on"+listener,fn); 55 } 56 } 57 58 addEvent(window,"load",footerFixed); 59 addEvent(window,"load",function(){ 60 checkFontSize(footerFixed); 61 }); 62 addEvent(window,"resize",footerFixed); 63 64 65 } 66 67 $(function(){ 68 funcFooter(); 69 $('input[name=check]').change(funcFooter); 70 }); 71 72})(jQuery);



回答1件
あなたの回答
tips
プレビュー