0

On my app i have 10 images which are all 200px x 200px, when i scroll i want to increase the top image to 400px x 400px

I have this so far to check if i am scrolling onto a div to change the size:

http://jsfiddle.net/c02m1q7w/6/

    $.fn.isOnScreen = function(){

    var win = $(window);

    var viewport = {
        top : win.scrollTop(),
        left : win.scrollLeft()
    };
    viewport.right = viewport.left + win.width();
    viewport.bottom = viewport.top + win.height();

    var bounds = this.offset();
    bounds.right = bounds.left + this.outerWidth();
    bounds.bottom = bounds.top + this.outerHeight();

    return (!(viewport.right < bounds.left || viewport.left > bounds.right || viewport.bottom < bounds.top || viewport.top > bounds.bottom));

};

$(window).scroll(function(){
    if($('#boxorange').isOnScreen() == true){
        $('#boxorange').css({"height":"400px"}); 
      $('#boxorange').css({"width":"400px"}); 
    } else{
            $('#boxorange').css({"height":"200px"}); 
        $('#boxorange').css({"width":"200px"});     }
});

But without creating separate if statements each time, which ever div is on top of the screen i want to increase in size but i am having no luck

1 Answers1

0

You are referring to the Mouse Wheel. You might consider the following code:

$(window).on("wheel", function(e) {
  if (e.originalEvent.wheelDelta / 120 > 0) {
    console.log('Wheel Up');
  } else {
    console.log('Wheel Down');
  }
});

See More: https://developer.mozilla.org/en-US/docs/Web/Events/wheel

Working Example: http://jsfiddle.net/Twisty/6jexbn07/

Hope this helps.

Twisty
  • 30,304
  • 2
  • 26
  • 45