I found this code here: https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_onscroll3 and while it works when I type the URL into my mobile browser, it doesn't work when I preview the file on my code editor (using Dreamweaver currently).
I've tried applying overflow: scroll to the HTML and body, I've also tried using scrollTop, scrollY, and applying the page offset to a variable such as var scrollY = window.pageYOffset; but can't seem to get it to work. I appreciate any help! I can see it's possible to trigger javascript functions based on mobile screen positions, but can't seem to find the solutions.
window.onscroll = function() {myFunction()};
function myFunction() {
if (document.body.scrollTop > 350 || document.documentElement.scrollTop > 350) {
document.getElementById("myImg").className = "slideUp";
}
}
.slideUp {
animation-name: slideUp;
-webkit-animation-name: slideUp;
animation-duration: 1s;
-webkit-animation-duration: 1s;
visibility: visible;
}
@keyframes slideUp {
0% {
opacity: 0;
-webkit-transform: translateY(70%);
}
100% {
opacity: 1;
-webkit-transform: translateY(0%);
}
}
@-webkit-keyframes slideUp {
0% {
opacity: 0;
-webkit-transform: translateY(70%);
}
100% {
opacity: 1;
-webkit-transform: translateY(0%);
}
}
body {height:1500px;}
.col-1 {float:left}
.col-2 {float:left;padding-left:25px;}
img {width:180px;height:100px;visibility:hidden;}
hr {margin-top:400px;}
<p>Scroll down this page.</p>
<p>When you have scrolled 350px from the top, an image will slide in.</p>
<hr>
<div class="col-1">
<img id="myImg" src="img_pulpit.jpg" width="304" height="228" alt="img">
</div>
<div class="col-2">
Just some text..
</div>