Giter Club home page Giter Club logo

onepage-scroll's Introduction

#One Page Scroll 1.3.1 by Pete R. Create an Apple-like one page scroll website (iPhone 5S website) with One Page Scroll plugin Created by Pete R., Founder of BucketListly

License: Attribution-ShareAlike 4.0 International

Requirement

jQuery (1.9.0 or later)

note: jQuery 1.9.0 or later is strongly recommended because using jQuery less than 1.8.3 and jquery.onepage-scroll.js together turns out to be a hash-based XSS vulnerabiliry.

see: http://jsfiddle.net/33WJx/

Demo

View demo

Compatibility

Modern browsers such as Chrome, Firefox, and Safari on both desktop and smartphones have been tested. Should work fine on IE8 and IE9 as well.

Basic Usage

One Page Scroll let you transform your website into a one page scroll website that allows users to scroll one page at a time. It is perfect for creating a website in which you want to present something to the viewers. For example, Apple's iPhone 5S website uses the same technique.

To add this to your website, simply include the latest jQuery library together with jquery.onepage-scroll.js, onepage-scroll.css into your document's <head> and call the function as follows:

<body>
  ...
  <div class="main">
    <section>...</section>
    <section>...</section>
    ...
  </div>
  ...
</body>

Container "Main" must be one level below the body tag in order to make it work full page. Now call the function to activate as follows:

$(".main").onepage_scroll({
   sectionContainer: "section",     // sectionContainer accepts any kind of selector in case you don't want to use section
   easing: "ease",                  // Easing options accepts the CSS3 easing animation such "ease", "linear", "ease-in",
                                    // "ease-out", "ease-in-out", or even cubic bezier value such as "cubic-bezier(0.175, 0.885, 0.420, 1.310)"
   animationTime: 1000,             // AnimationTime let you define how long each section takes to animate
   pagination: true,                // You can either show or hide the pagination. Toggle true for show, false for hide.
   updateURL: false,                // Toggle this true if you want the URL to be updated automatically when the user scroll to each page.
   beforeMove: function(index) {},  // This option accepts a callback function. The function will be called before the page moves.
   afterMove: function(index) {},   // This option accepts a callback function. The function will be called after the page moves.
   loop: false,                     // You can have the page loop back to the top/bottom when the user navigates at up/down on the first/last page.
   keyboard: true,                  // You can activate the keyboard controls
   responsiveFallback: false,        // You can fallback to normal page scroll by defining the width of the browser in which
                                    // you want the responsive fallback to be triggered. For example, set this to 600 and whenever
                                    // the browser's width is less than 600, the fallback will kick in.
   direction: "vertical"            // You can now define the direction of the One Page Scroll animation. Options available are "vertical" and "horizontal". The default value is "vertical".  
});

And that's it. Now, your website should work the same way Apple's iPhone 5S website does. You should be able to swipe up/down as well (thanks to Eike Send for his swipe events!) when viewing your website on mobile phones.

Keyboard Shortcuts

You can trigger page move with hotkeys as well:

Up arrow / Page Up

Pressing the up arrow or the page up key allows you to move the page up by one.

Down arrow / Page Donw

Pressing the down arrow or the page down key allows you to move the page down by one.

Spacebar

Pressing the space key allows you to move the page down by one.

Home

Pressing the home key brings you back to the first page.

End

Pressing the end key brings you to the last page.

Public Methods

You can also trigger page move programmatically as well:

$.fn.moveUp()

This method allows you to move the page up by one. This action is equivalent to scrolling up/swiping down.

  $(".main").moveUp();

$.fn.moveDown()

This method allows you to move the page down by one. This action is equivalent to scrolling down/swiping up.

  $(".main").moveDown();

$.fn.moveTo(page_index)

This method allows you to move to the specified page index programatically.

  $(".main").moveTo(3);

Callbacks

You can use callbacks to perform actions before or after the page move.

beforeMove(current_page_index)

This callback gets called before the plugin performs its move.

  $(".main").onepage_scroll({
    beforeMove: function(index) {
      ...
    }
  });

afterMove(next_page_index)

This callback gets called after the move animation was performed.

  $(".main").onepage_scroll({
    afterMove: function(index) {
      ...
    }
  });

If you want to see more of my plugins, visit The Pete Design, or follow me on Twitter and Github.

Other Resources

onepage-scroll's People

Contributors

gyugyu avatar i-am-kenny avatar kevva avatar lipis avatar peachananr avatar peterdemin avatar uniphil avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

onepage-scroll's Issues

Does not work in Opera 12

Scrollbar and header bar work correctly, but the main content does not change.
Version 12.16
Build 1860

Dragged elements become invisible

Hello. I wanted to use onepage-scroll in my project, but I've noticed that whenever I drag an element with native HTML5 Drag'n'drop (it's essential in this project), it disappears. You can see it even when you select some text and try to drag it (on other pages a ghost of the element is opaque, but visible). I'd be glad if you could examine this issue and suggest a solution different than dropping onepage-scroll :)
Best regards,
Mikołaj

Problem with Index (beforeMove/afterMove)

If one slides down, the index updates normally, but somehow it also increases index when going back up (like going from slide 1 to 0 returns index of 2). Another issue is the index doesn't update when using the pagination (rather, the beforeMove/afterMove doesn't fire?).

out on the last page button at the top

When it comes to have to go to the first page to the last page.
Presses the button to release the first page to the last page you want to put.
How can

iOS Forms

Hi there,

When you add any element from forms is not working at iOS.. Even in the demo if you add input type text then you are not able to selected..

This has to do something with the touch events...

Click to scroll to bottom

Trying to figure out a way to use moveBottom to build a scroll to bottom button.

Has anyone been able to do this?

Currently I am using
$("#scroll_bottom").click(moveBottom());

With no luck

Allow content after slides

I am encountering an issue where, if I have any content after the main slideshow, i'm not able to view it. Is there a way to have content after you main slideshow, similar to the iphone-5s website's footer section?

html, body overflow: hidden set in CSS

The 3rd line in onepage-scroll.css file sets (for html, body elements)

overflow: hidden;

IMHO, the overflow: hidden property must be set from within javascript, other wise, the page/site will break down and the user will be restricted to the first section only.

Adding the Navigation with our own text?

instead of using those circles, it would be nice to use something like:

<ul class="myNav>
<li><a href="#section1">Section 1</a></li>
<li><a href="#section2">Section 2</a></li>
<li><a href="#section3">Section 3</a></li>
</ul>

Thanks in advance

Broken link handling on touch devices (got a fix)

Now this patch fixes problem when doesn't work.

function touchstart(event) {
  var touches = event.originalEvent.touches;
  var touchedObject = touches[0].target;
  if (touchedObject.nodeName=='A'){
      $(touchedObject).click();
      return 1;
  }
  if(!(
        typeof($._data(touchedObject, "events")) !== 'undefined' 
        && $._data(touchedObject, "events").click != null
    )){
    startX = touches[0].pageX;
    startY = touches[0].pageY;
    $this.bind('touchmove', touchmove);
  }
  event.preventDefault();
}

Bug with link Android

hi seem to have a problem with link in android device
it's visible on your demo if you have android device
It's impossible to click on any link except bullet navigation.

beforeMove triggering multiple times

I've just noticed that beforeMove is triggering not just once, but incrementally. So after first scroll its triggering once, on the second slide twice and so on. If I go back from the second slide, then it will trigger this event 3 times. I guess that this is not the expected behaviour? Any ideas how to sort it out?

No license specified

The source code does not include the license. Thus, it may be possible to "download for free" this script, but it is not possible to use it or redistribute it on one's web site.

First Scroll Skips 2nd Page Jumps to 3rd

When the testing.apliiq.com/designyourowngift loads the first time in browser, scrolling down skips the page it's suppose to go to and jumps to the 3rd page!?
What gives?

Touchdevice onClick causes multichange

If you have a touch device & click and do not move on an empty space, and then do a touchmove, the pages changes for the amount of times you clicked.
On Touch only.
I used some onClick function and they didn´t worked, but the pages changed for the amount of onclick.

I added this work around for using onClick methods, but if you click on a "not onClick", it stills do the pagechange bug.

This is my function change:

function touchstart(event) {
     var touches = event.originalEvent.touches;

     if(!(typeof($._data(touches[0].target, "events")) !== 'undefined' && $._data(touches[0].target, "events").click != null)){
          console.log('do move stuff');
          if (touches && touches.length) {
              startX = touches[0].pageX;
              startY = touches[0].pageY;
              $this.bind('touchmove', touchmove);
            }
            event.preventDefault();
      }
 }

Breaks gesture back button

If you are on a machine such as a Mac which allows you to use two fingers to navigate backwards by swiping this site seems to break that. Every time you try to swipe to go back it just seems to scroll up and down.

moveTo not found

bildschirmfoto 2013-11-19 um 3 36 02 pm

moveUp and moveDown work perfectly, but moveTo is not found. What am I doing wrong?

Jquery cycle (iPad)

This does not work with jquery cycle plugin on ipad.
The links from the cycle plugin are not clickable on ipad, it does not animate the slides.

This is an issue on ios6 and 7.

No index when using $(".main").moveTo(3);

Hi,

i use the index to trigger some animations. But when I use the moveTo function the index is "undifined"

Am I doing anything wrong?

->

$(".main").onepage_scroll({
    sectionContainer: "section",
    asing: "ease", // Easing options accepts the CSS3 easing animation such "ease", "linear", "ease-in", "ease-out", "ease-in-out", or even cubic bezier value such as "cubic-bezier(0.175, 0.885, 0.420, 1.310)"
    animationTime: 2000, 
    direction: 'horizontal',
    afterMove: function(index) {
            console.log(index);
            if (index == 1) {
                // do something
            }
            if (index == 2) {
                // do something
            }
            if (index == 3) {
                // do something
            }
    },
});
$("#link").click(function() {
    $(".main").moveTo(2);
});

deactivate horizontal mouse scroll for vertical

Hi,

It seems the default of the plugin on trackpad (& mighty mouse) swipes is to scroll vertically even if you trackpad swipe horizontally. Is there a way for me to deactivate this function on the plugin so that horizontal swiping does not trigger the vertically scroll snapping?

In my layout you can see why this is a problem for me. I'm hoping to use onepage-scroll to trigger the vertical snapping of sections and horizontal will allow for free scrolling.

http://chrisriesner.com/cnyn-webzine-experiments/snap-scroll-ONEPAGESCROLL-NICESCROLL-cnyn/snap-scroll-ONEPAGESCROLL-NICE-clean.html

I appreciate any help!
thanks,
-chris

Callbacks

In order to start / stop animations within slides (as Apple does), it'd be nice to have callbacks functions on events

Text instead of bullets for pagination menu

Hi!

I am using this script for a website and it is one of the few that runs great so far. The only thing is that the code for the pagination is generated in the js, and I'm not so familiar with js. I want to display text (headers) and an image (little arrow thing) instead of bullets. Is there any way to do so? I could not find an option without completely altering the js and I have no idea what I'm doing there.

Url

How to remove # for id in urls change?
Thanks

Add LESS support

It would be nice to have the CSS in LESS format so people could include it in their sources and also it's easier to modify stuff..

iPhone 5s scrolling weird

Demo on iPhone 5s and the swipe doesn't work properly.
Doesn't go page by page.
Scrolling is flickering.

Keyboard support

Would be great to have up/down and pageup/pagedown support as well :)

6 Extra Pagination Added

Here I've defined 8 pages in the DOM but for some reason there are 6 extra pagination views. What gives?

http://testing.apliiq.com/designyourowngift

• peachananr said 'try to swap article for the sectionContainer in the function call'

but that didn't fix the 6 extra page views!?

I'm guessing here

var defaults = {
sectionContainer: "article", <---- here .main > article fixed it!!!!
easing: "ease",
animationTime: 1000,
pagination: true,
updateURL: false,
keyboard: true,
beforeMove: null,
afterMove: null,
loop: false,
responsiveFallback: false
};

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.