[英]How to insert a floating button on top right corner of screen in JS
Using only plain javascript, how to insert a button that will always be floating in the top right corner of the window above other elements ? 仅使用普通的javascript,如何插入一个按钮,该按钮将始终漂浮在其他元素上方的窗口的右上角?
So far I got: 到目前为止,我得到了:
var button = document.createElement("Button");
button.innerHTML = "Title";
button.style = "margin-top:0%;right:0%;position:absolute;"
document.body.appendChild(button);
Use top
instead of margin-top
and set a high z-index
使用
top
而不是margin-top
并设置较高的z-index
var button = document.createElement("Button"); button.innerHTML = "Title"; button.style = "top:0;right:0;position:absolute;z-index: 9999" document.body.appendChild(button);
You were almost there, but instead of using the margin-top
property, use the top
property and use position:fixed;
您几乎就在那儿,但是不要使用
margin-top
属性,而要使用top
属性并使用position:fixed;
instead of position:absolute;
代替
position:absolute;
. 。
var button = document.createElement("Button"); button.innerHTML = "Title"; button.style = "top:0;right:0;position:fixed;" document.body.appendChild(button);
将位置更改为固定,顶部更改为0
button.style = "top:0%;right:0%;position:fixed;"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.