Gurgen Hovsepyan
Gurgen Hovsepyan

Reputation: 406

jquery scroll is not working

I want to get scroll even and write this:

<script type="text/javascript">
        $(function () {
            $(window).scroll(function () {
                alert($("body").scrollTop());
            });
        });
    </script>

but when I run the page and scrolls, the page makes it black, it doesn't work correctlly. Can anyone please help me, why it is not working???

Upvotes: 0

Views: 1488

Answers (2)

Gurgen Hovsepyan
Gurgen Hovsepyan

Reputation: 406

I wrote a function that works then when I do scroll, and everything works fine. But if I do try debug in the browser, it same stops and shows the black screen.

$(window).scroll(function () {
     setBackground();
});

function setBackground() {
 // do something ...
}

Upvotes: 0

Bahdeng
Bahdeng

Reputation: 434

Your code works fine. Have you included the jquery script in your code ?

<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
        $(function (){
            $(window).scroll(function () {
                alert($("body").scrollTop());
            });
        });
    </script>

Upvotes: 1

Related Questions