I have this code, I tried to execute the if statement only one time. So the user will get only one alert show when getting to the middle of the page, after skipping the alert and keep scrolling he shouldn't get the alert again. so I added this PassedValue boolean variable but it doesn't get changed to true when the alert is shown.
$f = $.noConflict();
$f(document).ready(function() {
$f(window).scroll(function() {
var scrollAmount = $f(window).scrollTop();
var documentHeight = $f(document).height();
var scrollPercent = (scrollAmount / documentHeight) * 100;
var PassedValue = false;
//$(".3amal").append(scrollPercent);
if (scrollAmount > documentHeight * 0.3 && !PassedValue) {
alert('the user scrolled once!');
PassedValue = true;
} else {
//alert('Nothing done nothing to save');
}
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="container">
<div id="sidebar">
<ul>
<li><a id="aboutlink" href="#" style="position: sticky;top: 0;">auck</a></li>
<li><a id="projectslink" href="#">Projects</a></li>
<li><a id="resumelink" href="#">Resume</a></li>
<li><a id="contactlink" href="#">Contact</a></li>
</ul>
</div>
<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
<div class="3amal">Hellow i'm here</div>
</div><br/><br/><br/>
<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
<div id="content">
<div class="" id="about">
<p class="header">uck</p>
<p class="info">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure
dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</div>
<div class="sections" id="projects">
<p class="header">Projects</p>
<p class="info">Projects</p>
</div>
<div class="sections" id="resume">
<p class="header">Resume</p>
<p class="info">Resume</p>
</div>
<div class="sections" id="contact">
<p class="header">Contact</p>
<p class="info">Contact</p>
</div>
</div>
</div>
Aucun commentaire:
Enregistrer un commentaire