I wrote this page with the goal in mind of having a footer that runs along the bottom of the page that can be closed, and has a floating info box that appears when the footer is hovered over. I'm just learning JS, HTML and CSS now, so I'd appreciate any critiques on style.
Am I doing anything the long way? Is any of the JavaScript un-idiomatic? Please let me know!
What I'm not looking for advice on:
- I know that external CSS and JS would likely be preferable. I'm using internal JS and CSS to ease learning.
This is a very broad review request. I'd like opinions on any aspect of any of the languages used.
FooterTest.html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Footer Test</title>
<style>
body {
background-color: lightseagreen;
}
#floatingBox {
display: none;
position: fixed;
background-color: black;
color: white;
left: 0px;
top: 0px;
width: 50px;
height: 50px;
z-index: 1;
}
#fixedFooter {
display: block;
position: fixed;
background-color: bisque;
color: black;
left: 0px;
border-top: 10px double black;
bottom: 0px;
height: 20%;
width: 100%;
text-align: center;
z-index: 0;
}
#closeButton {
display: inline-block;
position: absolute;
right: 0px;
top: 0px;
color: white;
background-color: red;
width: 5%;
height: auto;
z-index: 1;
}
</style>
</head>
<body>
<div id="floatingBox">
Test Block
</div>
<footer id="fixedFooter">
<button id="closeButton">X</button>
</footer>
<script>
var fixedFooter = document.getElementById("fixedFooter");
var positionText = document.createElement('p');
var closeButton = document.getElementById("closeButton");
fixedFooter.appendChild(positionText);
var floatingBox = document.getElementById("floatingBox");
var defaultDisplay = "inline-block";
//To prevent the mouse from entering the floating box
var posBuffer = 10;
fixedFooter.onmousemove = function(e) {
var x = e.pageX;
var y = e.pageY;
positionText.innerHTML = formatPosition(x, y) + " - "
+ formatPosition(floatingBox.style.left, floatingBox.style.top);
setElementPosition(floatingBox, x + posBuffer, y + posBuffer);
};
fixedFooter.onmouseover = function(e) {
floatingBox.style.display = defaultDisplay;
console.log("\tMouse In");
};
fixedFooter.onmouseout = function() {
floatingBox.style.display = "none";
//setElementPosition(floatingBox)
console.log("\tMouse Out");
};
closeButton.onclick = function() {
fixedFooter.style.display = "none";
}
var setElementPosition = function(element, xPos, yPos) {
element.style.left = xPos + "px";
element.style.top = yPos + "px";
//console.log("Setting " + element + "'s position to " + formatPosition(xPos, yPos));
};
var formatPosition = function(x, y) {
return "(" + x + ", " + y + ")";
};
</script>
</body>
</html>