jQuery window handle scroll event

Description

jQuery window handle scroll event

View in separate window

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Executing a Function on Scroll Event in jQuery</title>
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<style>
    p{/*w  w w.j  a va2 s . c o  m*/
        width: 100%;
        padding: 50px 0;
        text-align: center;
        font: bold 34px sans-serif;
        background: #f0e68c;
        position: fixed;
        top: 50px;
        display: none;
    }
    .dummy-content{
        height: 600px;
        font: 34px sans-serif;
        text-align: center;
    }
</style>
<script>
$(document).ready(function(){
    $(window).scroll(function() {
        $("p").show().fadeOut("slow");
    });
});
</script>
</head>
<body>
    <p>Scroll Happened!</p>
    <div class="dummy-content">Scroll the viewport.</div>
    <div class="dummy-content">Scroll the viewport.</div>
    <div class="dummy-content">Scroll the viewport.</div>
    <div class="dummy-content">Scroll the viewport.</div>
    <div class="dummy-content">Scroll the viewport.</div>
</body>
</html>



PreviousNext

Related