Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

91
Views
I'd like to have an IMG fade slide in based on scroll position, works on desktop, but scroll position on mobile is always "0."

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>

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!