****2 UPDATE:**
I have seen update this works but div also moves with body
because document.documentElement.appendChild(div);
is not working and with document.body.insertBefore(div, document.body.firstChild);
div also moves down becuase of inserting in body
This is normal because you assign in a body
the style document.body.style.webkitTransform = // Chrome, Opera, Safari
document.body.style.msTransform = // IE 9
document.body.style.transform = "translateY(" + toolbarHeight + "px)";
The problem is a style.
Now there is a one possibility where you not assign this style to <body>
but only on <div>
and you can create inside the body
two <div>
.
NOTE You cannot create two <body>
in a file HTML because it 's a valid document HTML INFO
Where the first <div>
is the created of script that we discuss and other the rest of the <body>
in the <div>
.
Final you can assign the style on a div using document.getElementById("idofdiv").style.webkitTransform =document.getElementById("idofdiv").style.msTransform =document.getElementById("idofdiv").style.transform = "translateY(" + toolbarHeight + "px)";
And I shocked on the last comment.
****UPDATE:**
With the comment I understand you problem.
I copy new you script and paste on my notebook.
I open the file HTML on Firefox and Chromium (this is a name of Chrome on Ubuntu).
You can see the output and difference on imguru.
Now the problem is only on document.body.parent.style.webkitTransform='translateY(40px)';
I find why not function and this is not supported on Firefox
, IE
and OPERA
.
You see on the site
Now I change it with
document.body.style.webkitTransform = // Chrome, Opera, Safari
document.body.style.msTransform = // IE 9
document.body.style.transform = "translateY(" + toolbarHeight + "px)";
And the output is equal on Chrome. IMGURU
OLD:
I take you script and work in my notebook.
Inside the code there is a error on document.body.parent.style.webkitTransform='translateY(40px)';
and the error is:
TypeError: document.body.parent is undefined
This I not know that is and I delete.
Now I have other error TypeError: document.body is null
on var div = document.createElement("div");
I search on google and I fix this
Now I insert window.onload{ }
with inside you script and I insert the tag
for push body down.
<script type="text/javascript">
window.onload = function() {
//document.body.parent.style.webkitTransform ='translateY(40px)';
var div = document.createElement("div");
var br=document.createElement("br");
div.id="divs";
div.style.display='block';
div.style.width = "600px";
div.style.height = "100px";
div.style.background = "#C2E2FF";
div.style.color = "grey";
div.innerHTML = "my div";
document.body.insertBefore(br, document.body.firstChild);
document.getElementById("divs").style.fontStyle = 'italic';
document.getElementById("divs").style.position = "fixed";
}</script>
The output not view the body because the error (I say the error but this is not error) on style="fixed" because "replace" the (The element is positioned relative to the browser window).
I remove this and the output is correct.
I think that you have a problem with position and I suggest for you of use Firebug (tool of firefox and chrome) for find error
For information on the position you go on this site
Final DEMO