かわいい?いいえ。機能的?うん。20時間起きていて、何かをすばやく組み立てたいと思った場合の方法は次のとおりです. いつものように、予期しないプロジェクトの制約により、ソリューションが役に立たないというよりも悪いものになる可能性があります。ymmv (2 番目から 5 番目の関数は未使用、テンプレートの一部)
<!DOCTYPE html>
<html>
<head>
<script>
function byId(e){return document.getElementById(e);}
function newEl(tag){return document.createElement(tag);}
function newTxt(txt){return document.createTextNode(txt);}
function toggleClass(element, newStr)
{
index=element.className.indexOf(newStr);
if ( index == -1)
element.className += ' '+newStr;
else
{
if (index != 0)
newStr = ' '+newStr;
element.className = element.className.replace(newStr, '');
}
}
function forEachNode(nodeList, func)
{
var i, n = nodeList.length;
for (i=0; i<n; i++)
{
func(nodeList[i], i, nodeList);
}
}
window.addEventListener('load', mInit, false);
function mInit()
{
uploadBtn.addEventListener('mouseover', onBtnHover, false);
uploadBtn.addEventListener('mouseout', onBtnLeave, false);
}
function onBtnHover()
{
var btn = byId('uploadBtn');
var xPos, yPos;
xPos = btn.offsetLeft + btn.offsetWidth + 32;
yPos = btn.offsetTop;
var tgt = byId('popup');
var btnHeight, popupHeight;
btnHeight = btn.offsetHeight;
popupHeight = tgt.offsetHeight;
var vertOffset = (popupHeight-btnHeight) / 2;
var styleStr = "display: inline-block; visibility: visible;";
tgt.setAttribute('style', styleStr);
tgt.style.left = xPos+"px";
tgt.style.top = yPos-vertOffset+"px";
}
function onBtnLeave()
{
var tgt = byId('popup');
tgt.removeAttribute('style');
}
</script>
<style>
.controls
{
border: solid 2px #aaa;
padding: 16px;
}
#popup
{
visibility: hidden;
z-index: 2;
position: absolute;
max-width: 300px;
border-radius: 4px;
font-family: verdana;
background-color: #6495ee;
color: white;
padding: 8px;
font-size: 0.8em;
box-shadow: 4px 4px 2px rgba(0,0,0,0.3);
}
#popup b
{
background: white;
color: black;
padding: 4px;
border-radius: 4px;
border: solid 1px #777;
}
</style>
</head>
<body>
<div class='controls'>
<button id='uploadBtn'>Upload<br>file(s)</button>
</div>
<div id='popup'>To upload multiple files, <b>Shift</b> + click files in the dialog box..</div>
</body>
</html>