Skip to content

Instantly share code, notes, and snippets.

@spinpx
Last active January 22, 2016 15:26

Revisions

  1. spinpx revised this gist Jan 22, 2016. No changes.
  2. spinpx revised this gist Apr 18, 2015. No changes.
  3. spinpx revised this gist Apr 14, 2015. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions nextEvent.org
    Original file line number Diff line number Diff line change
    @@ -42,6 +42,8 @@ $(document).keydown(function(e) {
    #+END_SRC

    * Mobile Touch Event
    - touchstart
    - touchmove

    * Windows Scroll Bar
    + this method can be use dependent rather than above three method which usually use together to deal with different part behavior.
  4. spinpx revised this gist Apr 14, 2015. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions nextEvent.org
    Original file line number Diff line number Diff line change
    @@ -66,3 +66,7 @@ var scrollNext = function() {
    $(window).scroll(scrollNext);
    #+END_SRC

    * Plugins
    + there are some open source plugins easy to realize the scroll effect.
    - https://github.com/alvarotrigo/fullPage.js
    - https://github.com/peachananr/onepage-scroll
  5. spinpx revised this gist Apr 14, 2015. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions nextEvent.org
    Original file line number Diff line number Diff line change
    @@ -27,7 +27,7 @@ $(document).keydown(function(e) {
    - onmousewheel :: IE6/7/8

    + you can add event separately by =addEventListener=, or use Jquery's =bind= method.
    + also you should consider duplicate events. you can use time period to avoid this situation.
    + also you should consider repeated events. you can use time period to avoid this situation.

    #+BEGIN_SRC js
    $(document).bind('mousewheel DOMMouseScroll MozMousePixelScroll', function(event) {
    @@ -46,13 +46,13 @@ $(document).keydown(function(e) {
    * Windows Scroll Bar
    + this method can be use dependent rather than above three method which usually use together to deal with different part behavior.
    + If you are not a height 100% page. Key down/up, Mouse wheel, touch Down/up all can be convert to scroll the window.
    + I use Jquery's =scrollTop= method to realize the effect.Addtionally, Jquery provide =scroll=, =scrollLeft=.
    + I use Jquery's =scrollTop= method to realize the effect. Addtionally, Jquery provide =scroll=, =scrollLeft=.
    - obj.scrollTop() :: just return the vertical position of the scroll bar
    - obj.scrollLeft() :: return the horizontal position of the scroll bar
    - obj.scroll(func) :: the same as obj.bind('scroll'), trigger when you scroll
    #+BEGIN_SRC js
    var oldPos = $(window).scrollTop;
    var scrollNext = function() {
    var oldPos = 0;
    var pos = $(window).scrollTop();
    if (pos > oldPos) {
    //next
  6. spinpx revised this gist Apr 14, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion nextEvent.org
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    #+TITLE: scroll events under Javascript

    + Recently, I wrote an single page site like slides. It involes some keyboard,mouse wheel events.
    + Recently, I wrote an single page site like slides. It involves some keyboard,mouse wheel events.
    + Depend on Jquery.
    + once you have binded the event, remains is easy. just needs margin or padding the content area 100%, or jump to the target anchors.

  7. spinpx revised this gist Apr 13, 2015. No changes.
  8. spinpx revised this gist Apr 13, 2015. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions nextEvent.org
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,8 @@
    #+TITLE: scroll events under Javascript

    + Recently, I write an single page site like slides. It use some keyboard,mouse wheel events.
    + And I use Jquery as my tool.
    + once you have bind the event, remain things is easy. you just margin or padding the content area 100%, or go to target anchor.
    + Recently, I wrote an single page site like slides. It involes some keyboard,mouse wheel events.
    + Depend on Jquery.
    + once you have binded the event, remains is easy. just needs margin or padding the content area 100%, or jump to the target anchors.

    * Keyboard Event
    #+BEGIN_SRC js
    @@ -17,7 +17,7 @@ $(document).keydown(function(e) {
    })
    #+End_Src

    + notice that do not bind keyboard event once you are in input area
    + notice that do not bind keyboard event while you are in input area
    + Jquery also provide =keypress=, =keyup=, =focusout= these related methods.

    * Mouse Wheel Event
  9. spinpx revised this gist Apr 13, 2015. No changes.
  10. spinpx created this gist Apr 13, 2015.
    68 changes: 68 additions & 0 deletions nextEvent.org
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,68 @@
    #+TITLE: scroll events under Javascript

    + Recently, I write an single page site like slides. It use some keyboard,mouse wheel events.
    + And I use Jquery as my tool.
    + once you have bind the event, remain things is easy. you just margin or padding the content area 100%, or go to target anchor.

    * Keyboard Event
    #+BEGIN_SRC js
    $(document).keydown(function(e) {
    var tag = e.target.tagName.toLowerCase();
    switch(e.which) {
    case 38:
    if (tag != 'input' && tag != 'textarea') goPrev();
    break;
    default: return;
    }
    })
    #+End_Src

    + notice that do not bind keyboard event once you are in input area
    + Jquery also provide =keypress=, =keyup=, =focusout= these related methods.

    * Mouse Wheel Event
    + There are three mouse wheel event in general:
    - mousewheel :: IE9,Chrome,Safari,Opera
    - DOMMousescroll :: Firefox
    - onmousewheel :: IE6/7/8

    + you can add event separately by =addEventListener=, or use Jquery's =bind= method.
    + also you should consider duplicate events. you can use time period to avoid this situation.

    #+BEGIN_SRC js
    $(document).bind('mousewheel DOMMouseScroll MozMousePixelScroll', function(event) {
    event.preventDefault();
    var delta = event.originalEvent.wheelDelta || -event.originalEvent.detail;
    if (delta < 0) {
    //down
    } else {
    //up
    }
    });
    #+END_SRC

    * Mobile Touch Event

    * Windows Scroll Bar
    + this method can be use dependent rather than above three method which usually use together to deal with different part behavior.
    + If you are not a height 100% page. Key down/up, Mouse wheel, touch Down/up all can be convert to scroll the window.
    + I use Jquery's =scrollTop= method to realize the effect.Addtionally, Jquery provide =scroll=, =scrollLeft=.
    - obj.scrollTop() :: just return the vertical position of the scroll bar
    - obj.scrollLeft() :: return the horizontal position of the scroll bar
    - obj.scroll(func) :: the same as obj.bind('scroll'), trigger when you scroll
    #+BEGIN_SRC js
    var scrollNext = function() {
    var oldPos = 0;
    var pos = $(window).scrollTop();
    if (pos > oldPos) {
    //next
    }
    if (pos > oldPos) {
    //prev
    }
    oldPos = pos;
    }

    $(window).scroll(scrollNext);
    #+END_SRC