SpaceApe
SpaceApe

Reputation: 639

if ScrollTop an exact value

I've got a script that locks the users screen when the scroll past a certain point (1500).

<script type="text/javascript">
    $(document).scroll(function () {
    
        if ($(document).scrollTop() >= 1500) { 
        $.scrollLock(true);}
    });
</script>

This works. The users have to solve a question before they can continue. When they click the pink button they will get a pop up that they answered the question correct or wrong. When they answer it correct the lock script should be deactivated.

So I used $.scrollLock(false); when the answer is correct. This doesn't work. I can see it tries to scroll, but it gets locked again. So what I think the problem is the code above says: when the user is on 1500 or beyond (1501, 1502, etc..) the script starts to work.

How do I change this code so it will only work on 1500 and not on any other value? I tried changing >= to == but this doesn't work.

Hope you can help me.

Upvotes: 0

Views: 153

Answers (1)

Genzotto
Genzotto

Reputation: 1974

You should look at this:

http://www.anthonymclin.com/jquery-lockscroll-121#.U4cZ8Xbm63E

Then you can re-write your code in this way:

$(document).scroll(function () {
    if ($(document).scrollTop() >= 1500) { 

        $('container').lockScroll({
            'triggerElement' : $('element_to_trigger_scrolling'),
        });
    }
});

Upvotes: 0

Related Questions