deep dive
by trentHarlem
HTML
<div id="section1">
<h2>Section 1 (surface)</h2>
<div id="myBoat">
<h3 id="myBoatHeader">
<•_BOAT_•>
</h3>
<p><button class="dive">Dive</button></p>
<a href="#section2" class="dive fff">vvv DOWN vvv</a>
</div>
<div class="high dive">
</div>
</div>
<div id="section2">
<h2>Section 2 (floor)</h2>
<a href="#section1" class="fff">^^^ UP ^^^</a>
</div>
CSS
body {
background: linear-gradient(dodgerblue, midnightblue);
scroll-behavior: smooth;
transition: all 4s ease-in;
}
#section1 h2 {
background-color: transparent;
text-shadow: 5px 5px 20px #ffffff55;
}
.high {
height: 1500px;
transition: all 2s ease-in;
}
.dive:focus {
-webkit-animation-name: dive;
-webkit-animation-duration: 11s;
-webkit-animation-iteration-count: once;
-webkit-animation-direction: down;
-webkit-animation-timing-function: linear;
}
/* #box:hover {
-webkit-animation-play-state: paused;
} */
@-webkit-keyframes dive {
0% {
margin-top: 0px;
}
50% {
margin-top: 1500px;
}
100% {
margin-top: 0px;
}
}
#section2{
height: 100px;
color: whitesmoke;
margin-bottom: 30px;
}
#myBoat {
position: absolute;
width: 120px;
text-align: center;
}
#myBoatHeader {
padding: 10px;
cursor: move;
background-color: brown;
color: #fff;
}
#myBoatHeader:hover {
box-shadow: 0px 5px 25px #ffffff55;
}
.fff {
color: #fff;
}
button {
cursor: grab;
}
JavaScript
//Make the DIV element draggagle:
dragElement(document.getElementById("myBoat"));
function dragElement(elmnt) {
var pos1 = 0, pos2 = 0, pos3 = 0, pos4 = 0;
if (document.getElementById(elmnt.id + "Header")) {
/* if present, the header is where you move the DIV from:*/
document.getElementById(elmnt.id + "Header").onmousedown = dragMouseDown;
} else {
/* otherwise, move the DIV from anywhere inside the DIV:*/
elmnt.onmousedown = dragMouseDown;
}
function dragMouseDown(e) {
e = e || window.event;
e.preventDefault();
// get the mouse cursor position at startup:
pos3 = e.clientX;
pos4 = e.clientY;
document.onmouseup = closeDragElement;
// call a function whenever the cursor moves:
document.onmousemove = elementDrag;
}
function elementDrag(e) {
e = e || window.event;
e.preventDefault();
// calculate the new cursor position:
pos1 = pos3 - e.clientX;
pos2 = pos4 - e.clientY;
pos3 = e.clientX;
pos4 = e.clientY;
// set the element's new position:
elmnt.style.top = (elmnt.offsetTop - pos2) + "px";
elmnt.style.left = (elmnt.offsetLeft - pos1) + "px";
}
function closeDragElement() {
/* stop moving when mouse button is released:*/
document.onmouseup = null;
document.onmousemove = null;
}
}