Javascript animation is not running -
i'm trying create animated menu slides , down. unfortunately it's not working. i've checked error console , there no syntax errors. here's javascript:
function showlayer() { var hiddenlayer = document.getelementbyid("mainmenu"); var layerposition = parseint(hiddenlayer.style.bottom); if (layerposition > 700) { hiddenlayer.style.bottom = (layerposition + 5) + "px"; settimeout("showlayer()", 20); } } function hidelayer() { var hiddenlayer = document.getelementbyid("mainmenu"); hiddenlayer.style.bottom = "700px"; }
here's whole context:
<script type="text/javascript"> function showlayer() { var hiddenlayer = document.getelementbyid("mainmenu"); var layerposition = parseint(hiddenlayer.style.bottom); if (layerposition > 700) { hiddenlayer.style.bottom = (layerposition + 5) + "px"; settimeout("showlayer()", 20); } } function hidelayer() { var hiddenlayer = document.getelementbyid("mainmenu"); hiddenlayer.style.bottom = "700px"; } </script> <style type="text/css"> div#mainmenu { position: absolute; bottom: 700px; left: 9px; width: 600px; height: 350px; border-style: solid; background-color: rgb(0, 0, 0) ; border- width: 3px; border-top-right-radius: 7px; border-top-left-radius: 7px; } div#mainbutton { position: absolute; top: 674px; left: 12px; width: 28px; height: 28px; border-style: solid; border-color: rgb(255, 255, 255); border-width: 1px; border-radius: 4px; } div#mainbuttontext { position: absolute; top: 679px; left: 22px; color: rgb(255, 255, 255); font-style: normal; font-size: 18px; font-family:"arial"; } </style> <div id="mainbutton"></div> <div id="mainmenu" onclick="showlayer('mainmenu')"> </div> <div id="mainbuttontext">f</div> </body>
i think found problem! it's strange , can't explain it, get style in javascript, css must inline (to set style it's not necessary).
so modified code placing css inline.
html :
<div id="mainmenu" style="position:absolute;bottom:100px;" onclick="showlayer('mainmenu');">click me!</div> <!--i wrote 100px test, can change , modify js-->
js :
function showlayer() { var hiddenlayer=document.getelementbyid("mainmenu"); var layerposition=parseint(hiddenlayer.style.bottom); if(layerposition>50) { hiddenlayer.style.bottom=(layerposition+5)+"px"; settimeout("showlayer()",20); } } function hidelayer() { var hiddenlayer=document.getelementbyid("mainmenu"); hiddenlayer.style.bottom="700px"; }
fiddle : http://jsfiddle.net/8mwfv/
and here fiddle shows not inline css doesn't works : http://jsfiddle.net/kfurp/
Comments
Post a Comment