Code Monkey home page Code Monkey logo

scrollify's Introduction

A jQuery plugin that assists scrolling and snaps to sections. Touch optimised.

Demo

http://projects.lukehaas.me/scrollify.

More examples

Scroll animations

Layered scrolling

Pagination

Full page video

Header and footer

Dynamic content

Basic setup

Scrollify requires jQuery 1.7+.

The most basic setup is as follows:

<!doctype html>
  <html>
    <head>
      <script>
        $(function() {
          $.scrollify({
            section : ".example-classname",
          });
        });
      </script>
    </head>
    <body>
      <div class="example-classname"></div>
      <div class="example-classname"></div>
    </body>
  </html>

Configuration

This is the default configuration:

$.scrollify({
    section : ".example-classname",
    sectionName : "section-name",
    interstitialSection : "",
    easing: "easeOutExpo",
    scrollSpeed: 1100,
    offset : 0,
    scrollbars: true,
    standardScrollElements: "",
    setHeights: true,
    overflowScroll: true,
    updateHash: true,
    touchScroll:true,
    before:function() {},
    after:function() {},
    afterResize:function() {},
    afterRender:function() {}
  });

Options

section A CSS selector for the sections of the page.

sectionName Scrollify lets you define a hash value for each section. This makes it possible to permalink to particular sections. This is set as a data attribute on the sections. The name of the data attribute is defined by sectionName.

interstitialSection A CSS selector for non-full-height sections, such as a header and footer.

easing Define the easing method.

offset A distance in pixels to offset each sections position by.

scrollbars A boolean to define whether scroll bars are visible or not.

standardScrollElements A CSS selector for elements within sections that require standard scrolling behaviour. For example standardScrollElements: ".map, .frame".

setHeights A boolean to define whether Scrollify assigns a height to the sections. True by default.

overflowScroll A boolean to define whether Scrollify will allow scrolling over overflowing content within sections. True by default. (This will be false if scrollbars is false)

updateHash A boolean to define whether Scrollify updates the browser location hash when scrolling through sections. True by default.

touchScroll A boolean to define whether Scrollify handles touch scroll events. True by default.

before(index, sections) A callback that is fired before a section is scrolled to. Arguments include the index of the section and an array of all section elements.

after(index, sections) A callback that is fired after a new section is scrolled to. Arguments include the index of the section and an array of all section elements.

afterResize() A callback that is fired after the window is resized.

afterRender() A callback that is fired after Scrollify's initialisation.

Methods

$.scrollify.move("#name");

The move method can be used to scroll to a particular section. It can be passed the index of the section, or the name of the section preceded by a hash.

$.scrollify.instantMove("#name");

The instantMove method can be used to scroll to a particular section without animation. It can be passed the index of the section, or the name of the section preceded by a hash.

$.scrollify.next()

The next method can be used to scroll to a panel that immediately follows the current panel.

$.scrollify.previous()

The previous method can be used to scroll to a panel that immediately precedes the current panel.

$.scrollify.instantNext()

The instantNext method can be used to scroll to a panel that immediately follows the current panel, without animation.

$.scrollify.instantPrevious()

The instantPrevious method can be used to scroll to a panel that immediately precedes the current panel.

$.scrollify.destroy()

The destroy method removes all Scrollify events and removes set heights from the panels.

$.scrollify.update()

The update method recalculates the heights and positions of the panels.

$.scrollify.current()

The current method returns the current section as a jQuery object.

$.scrollify.currentIndex()

The currentIndex method returns the current section index, starting at 0.

$.scrollify.disable()

The disable method turns off the scroll snap behaviour so that the page scroll like normal.

$.scrollify.enable()

The enable method resumes the scroll snap behaviour after the disable method has been used.

$.scrollify.isDisabled()

The isDisabled method returns true if Scrollify is currently disabled, otherwise false.

$.scrollify.setOptions()

The setOptions method can be used to change any of the initialisation options. Just parse it an options object.

Issues

If you're working with Scrollify and having issues, please post your questions to Stackoverflow and tag it with 'jquery-scrollify'.

If you think the issue is with Scrollify itself, please check the open issues to see if it has already been logged. If it hasn't, please open a ticket with a detailed description of what you're seeing and details of the device and browser version you're seeing it on.

FAQ

  • Do I have to use the section element for Scrollify sections?

No, Scrollify sections have no relation to the section element. Scrollify sections can be any element you want.

  • Can sections receive an active class when they are scrolled to?

Yes, this is something you can easily implement in either the before or after callbacks (which ever suites you best).

  • Can Scrollify be used for horizontal scrolling?

No, this is not currently supported.

  • Can I disable Scrollify on mobile?

Yes. Scrollify works well on mobile but if you need to disable it you can use the disable method. $.scrollify.disable().

  • Why am I not able to scroll to the bottom of a section?

You must ensure that there is no collapsed content within your sections. This often happens when you have floated content within a container that isn't cleared. All content must be properly contained in order for an accurate section height to be calculated.

  • Why are section heights increasing on resize?

This happens when your browser is running in Quirks Mode, usually as the result of an incorrect doctype.

Setup with SectionName

Scrollify appends a hash value to the URL for each section, this allows for permalinking to particular sections. To define the hash value for each section you need to set a data-attribute on your sections. This data attribute can be called anything you like. The default is "section-name", but if you'd like something else then you'll need to define it with the sectionName option.

<!doctype html>
  <html>
    <head>
      <script>
        $(function() {
          $.scrollify({
            section : ".section-class-name",
            sectionName : "section-name"
          });
        });
      </script>
    </head>
    <body>
      <div class="section-class-name" data-section-name="home"></div>
      <div class="section-class-name" data-section-name="about"></div>
    </body>
  </html>

Installation

  • bower - bower install Scrollify
  • npm - npm install jquery-scrollify

Browser Support

IE Chrome Firefox Opera Safari
IE 8+ ✔ Chrome ✔ Firefox ✔ Opera ✔ Safari ✔

Acknowledgements

Browserstack

Special thanks to Browserstack for supporting Scrollify.

RunJS

Also, make sure to check out RunJS. RunJS is a JavaScript playground that evaluates your code as you type and gives instant feedback. It's ideal for prototyping ideas or trying out new libraries.

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -m 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :)

License

MIT License

scrollify's People

Contributors

afrastgeek avatar christingruber avatar dominicfallows avatar fthues avatar jessehigson avatar lukehaas avatar marcoherzog avatar markcarlson avatar martinczerwi avatar niknbr avatar rossmerriam avatar scuben avatar speakincode avatar steveeakin avatar tejasbubane avatar timdk avatar ttouka avatar vishnurk avatar xph03n1x avatar zhangxh6931 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

scrollify's Issues

padding not working

Hi, i just tried to make a div positioned in the center of a section using padding, but the padding is just increasing the size of the whole section and not doing what i want it to do, I am using box sizing but padding is still increasing the size of the select. Captain, I'm requesting assistance!! any kind of way to center div is needed, because i tried all i knew and no results.

Easing method "Swing" has a choppy transition with keyboard navigation

Using the 'up arrow' and 'down arrow' keys will transition to next section, but it's not a smooth transition. Using preventDefault() for these keys allows for a smooth transition, however it prevents any scrolling when the window height is less than the section height.

As a work-around i'm using the linear easing instead.

Magic Mouse Scrolling

I've had an issue with Scrollify when using the Apple Magic Mouse, it seems that this mouse is too sensitive for Scrollify so the page will often jump multiple scrolls on a small swipe of the wheel.

I've found that changing the timeoutId value 35 in wheelHandler to a higher value such as 150 can alleviate the problem. It would be good if this value was optmized for the input type or at least customizable (sensitivity option?) so we could fix the issue with needing to modify the Scrollify JS.

This issue was observed with scrollbars: false set, may not affect the default settings.

Plugin not animating

Hi, the plugin is sending you directly to the section defined after a click event or a mouse wheel event, but it's not animating.

Height set by Scrollify

Hi,

Basically I've got sections at 100vh, technically that should mean the plugin shouldn't set heights? It does - any way around it? Also I have one section that's 200vh, same applies here. I would like it to remain 200vh.

Thank you!

$.scrollify("move","#myAnchorName") is not working

Hi there,

I am currently able to scroll successfully between sections in a very nice manner. My issue arises with the onclick event and the scrollify move function. It does not seem to work with me.

Browser: Chrome

I can't reactivate scrollify after use $.scrollify.destroy()

This is my code

var scrollifyOption = {
        section: '.frame',
        scrollSpeed: 400,
        afterResize: function() {
            if( $(window).width() < 768 ) {
                $.scrollify.destroy();
            }
        },
    }

    if( $(window).width() > 768 ) {
        $.scrollify(scrollifyOption);
    }

    $(window).resize( $.debounce('300', function() {
    if( $(window).width() > 768 ) {
        $.scrollify(scrollifyOption);
    }
}));

I also try this https://github.com/lukehaas/Scrollify/blob/master/jquery.scrollify.js from this post #32 and this is console from Chrome

console.log

callback question

hello!

first off, this plugin is wonderful, so thankyou for that. in the docs you describe the callbacks as including 'Arguments include the index of the section and an array of all section elements.'.

i need to construct next / prev buttons which, using the section element array, should be pretty straightforward. it's a pretty simple question i think, but how do i go about leveraging these arguments?

thanks again :)

How to make autoheight for section

Do you have any function? How are we going to do?

Example:

<div id="sect1"></div>
<div id="sect2" style="height: 500px"></div>

Thanks.

Safari & Chrome ReLoad Issue

Hello,
I am having an issue with Safari & Chrome, the plugin works great on load however if you refresh it loads the first panel/section and does not allow scrolling to any of the other panels.

You can scroll down using the scrollbar but this automatically jumps back to the first panel,

I have tried removing all over scripts and run with just the basic code but this issue still persists.

Please can you tell me how I can fix this?

I am using:
Version 7.1.7 of Safari.
Version 44.0.2403.155 (64-bit) Chrome

Thanks

NJ

Fade in

Hello, do you think transitions can be added (fade-in, fade-out)?

I've tried checking with viewPortChecker if content is visible and add different classes based on that, but it seems that when I use scruffily viewPortChecker won't detect either the classes are visible or not. Can you guide me a bit in what 'before' and 'after' methods do ?

Thanks,
Alex.

Links not working on mobile devices

Hello,
Firstly thanks for the great plugin. Its really easy and well documented.
I have an issues with mobile devices. I've added this plugin to one of my client site and none of the links or button works in mobile devices. Whenever i try to click a link or a button. It directly scrolls down.

Navigation Menu

Hi! thanks for this plugin, I really want to use it on my page.

Can we add a navigation menu on top of the page? So, when you click on the first menu it goes to section 1 and so on...? And if possible with active class?

ask for help

<! doctype html>
<html>
    <head>
        <script src="jquery-2.1.1.min.js"></script>
        <script>
            $(function(){
                $(".test").css({"height":$(window).height()});
                $.scrollify({
                    section:".test"
                });
            });
        </script>
        <style>
            .test{
                width: 100%;
            }
            .red{
                background-color: red;
            }
            .blue{
                background-color: blue;
            }
        </style>
    </head>
    <body>
        <section class="test red"></section>
        <section class="test blue"></section>
    </body>
    <script src="jquery.easing.1.3.js"></script>
    <script src="scrollify.min.js"></script>
</html>

browser always remind :“Uncaught TypeError: Cannot read property 'length' of undefined ”

Remaining content outside from the section

Thanks for this great plugin.

Is there a possibility we can scroll the other content even it is outside/below from the sections?

E.g
Section 1 - Occupies 100% height
Section 2 - Occupies 100% height
Footer - Doesn't occupy the entire height of the page

For the moment, your plugin stops at the last section(Section 2). I can still view the footer using the scrollbar but not on mousewheel.

Hope this make sense...

Problems using

Dear developer, can you tell me how to use this plugin zhugery from start to finish?
I installed it and it does not work.
Please,write full HTML cod so that i can see
Excuse me, please.

Don't Resize the Window?

Is there a way to not resize the section? I don't want to change the height of any elements but would like theme to land center of my screen.

reset scrollify ?

On a current site, i'm handling window resize, so i reapply scrollify right after the user resize the browser. But up/down key navigation doesn't seem to update the height size, so more than one page is scrolled on each keypress.

Is there a way to completely reset scrollify with new values ?

Magic Mouse Inputs

Magic Mouse hard swipes seems to skip over sections, I see this happening on the demo page as well. Is there a fix for this? I see people adjusting timeouts with other issues but I doesn't seem to fix the issue here. So far I've seen this behavior in Safari and Chrome.

Conflict when using sections with number IDs

This took me way too long to figure out.

I had given my sections ID numbers like <section id="0"></section>, <section id="1"></section>, etc. This caused the animation when scrolling down to run backwards and scroll up, because there was a conflict between the hash in the URL and the ID of the section. Anyways it works fine if you use anything other than a number for the section IDs. Maybe mention this in the documentation?

Destroying and re-initializing

Hi there, I've run into the same issue as some others that the animation often jumps over two sections at once, presumably because of "kinetic" scrolling behaviour in modern browsers (confirmed using Chrome, Safari and Firefox on a MBP both with Magic mouse and built-in trackpad). The same issue can be seen in other, similar libraries.

I'm trying to get round this by destroying and then re-initializing scrollify after a setTimeout, but when I try to run scrollify again I get the error message "Uncaught TypeError: Cannot set property '0' of null" (the null in question here is the overflow property).

Here's the code I'm using to try to accomplish this:

    var scrollifySections = function () {

        $.scrollify({
            section: '.js-scroll-panel',
            scrollSpeed: 800,
            after: function() {
                $.scrollify.destroy();
                setTimeout( function() {
                    scrollifySections();
                }, 1000 );
            }
        });

    }
    if ( $(window).width() > 768 ) {
        // Run the first time
        scrollifySections();
    }

Scrollify not working with overflow-x: hidden [Chrome only]

Hello!
The problem is in using the library in conjunction with Google Chrome (Version 43.0.2357.132 (64-bit)) and a simple style CSS stylesheet (w/overflow-x:hidden in html & body tags). Basically, once I initialize scrollify, I can't use the mouse scroll and I can only scroll down with the arrows (And not getting the animation effect).
I try the same in iceweasel and it works.
Here's the setup: https://jsfiddle.net/5k9sn81c/
Cheers! And thxs for the library!

Prev/Next jump to anchor

Hi, great plugin.

What about prev/next buttons on mouse/browser or mobile phone(prev)? It get back to section but withouth animation, (on mobile when we scroll many time by sections it takes and remember every anchors so if u want go back from entire page by one click of prev button (as it looks like one page) it's hard). Is there any way to animate by sections on prev/next buttons or just turn it off? Or script only works with anchors and there is nothing to do with it?

Regards

Assign plugin functionality to a certain part of the website

Why not implement the plugin following the convention of $('#desired-container').scrollify({section: 'desired-section-element'}); so it can be assigned to only specific parts of the website? I have a one page layout but it is two-parted (50/50 left and right) and I only want the right part to have this functionality - when I apply it as it is now, only the hash changes but no scroll effect whatsoever...

Preloading content of next and previous section

I would like to preload the respective content of the next and previous sections that follow after the current section.

A similar return like $.scrollify.current(); would be useful.
For instance: $.scrollify.nextsec() or $.scrollify.prevsec()

Would you recommend any other way of achieving such a preloading solution?

Phones

Hi,dear developer.
Can you suggest how to disable the script on the phones?
How to disable the script after he came to my desired div(slider) that went beyond the usual scrolling.

Problems with scrolling up

Scrolling up only works for me if the content of a section fills up over 100% of the screen height. Scrolling down works just fine. What could be the issue? Thanks.

iframes break scrollify on mobile

Hey, lovely plugin, thanks.

Only problem is that it break on mobile if there's an iframe - you can see it at earlybirdcollective.co working fine on desktop, not at all on mobile (blank on Chrome on iOS9, or blank with error message 'A problem occurred with this webpage, so it was reloaded' on safari iOS9.)

Been driving me nuts, i'm relatively new to this, so any help much appreciated!

D

swipeScroll reaction time

Hi there, very lovely plugin!
The only issue i have is with when using a mac's trackpad or magicmouse, the scrolling has a slight reaction shift. I tried modifying the timeGap option, but it didn't do anything.
It would by very nice if you could fix this :)

Scrollify.js has Fatal bug

Its On some Google browser can not scroll mouse,but I down Like Google browser can scroll mouse

why is it ?

Its and the operating system has a relationship right ?

Scrollify on mobile devices

Hello! I have a question. How can i disable this JavaScript plugin on mobill phpnes and tablets? I will be very grateful if you'll give me the answer!!

Prove a package.json

It would be nice, if you can provide a package.json as well (not just a bower.json). Thus, Scrollify can be installes via NPM as well: see npm/npm#7232

section height Increase

Hello, I don't know if i'd call this an issue.
a section in my page has information which goes beyond the section and remaining section misbehaves.
What i am trying to say is, I have added a load more button which loads more content in the same section. and remaining section in the bottom totally misbehaves with scrolling.
Is there anything i could fix this ?

bugs not always scroll works

Hi again,

I updated from v.0.1.7 to 0.1.9. There are new method destroy. Which is great but there are some problems:

  1. Scroll works not always on mousewheel.
  2. On key press, the section is not entirely scrolled. Need to press twice to scroll a section.
  3. On using destroy method: Uncaught TypeError: Cannot set property '0' of null(anonymous function) @ jquery.scrollify.js:369m.extend.each @ jquery.min.js:2m.fn.m.each @ jquery.min.js:2sizePanels @ jquery.scrollify.js:363(anonymous function) @ jquery.scrollify.js:331

menu callback not working

Hello, This is my second project using scrollify. I am not able to scroll pages with links in the menu.
I have created a modal which acts as a primary menu in all the pages.
This is how my code looks like.

<div class="modal">
  <a href="#section1">Section 1</a>
  <a href="#section2">Section 2</a>
 <a href="#section3">Section 3</a>
</div>

<section id="section1"></section>
<section id="section3"></section>
<section id="section3"></section>

The above process did not work well. it would only sometime scroll the page.

then going though the documentation and issues thread. I tried the following code,

 function myTop() {
   $.scrollify.move("#top");
 }

<div class="modal">
  <a href="" onclick="myTop()">Section 1</a>
 <a href="#section2">Section 2</a>
 <a href="#section3">Section 3</a>

This did work but it reloaded the page and took me to the section1.
Am i missing something. Your response would be very much grateful/

Section height > browser height -> No scrolling.

Hi!
Very nice plugin!

My issue was closed in #12 but for some reason it doesn't seem to work. I'm using vh / vw as units, could it have anything to do with that?

Where in the code did you implement this?

Thanks!!

Apply scrollify.js to only certain sections on the page, and let other sections scroll normally

Hi Lukehaas,
Nice plugin. but what if I have to apply it to certain sections on a page.
Actually I am having a small footer at the end of all sections.
when I scroll to the last section, and try to scroll to the footer. the plugin does not allows me to do so.
all the sections are having a height of 100%. but the footer is set to height auto which how should i exclude the footer from the plugin and allow it to be scrolled normally.

Content area without scroll

Can we use scrollify like a slider? For example I have 3 sections. After that standart content divs starting but scrollify stopped at the last section. Page is not scrolling down. How can we work like this?

addEventListener not supported in IE8 and earlier

At line 420, addEventListener is used, however this wasn't implemented in Internet Explorer until version 9.

Here is the code I used to get around it:
if (window.addEventListener) {
window.addEventListener("orientationchange", util.handleResize, 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.