View on GitHub

Fixnel.js

fixnel.jsは、iOSのUIである慣性スクロールを再現したJSです。
位置固定のfixとpanelを合成した造語です。
右のサンプルはWebKit系ブラウザでのみ動作します。(スマートフォン向けです)

fixnel.js give a likes iOS UI with inertia scrolling.
"fixnel" is combine the word of "fix" and "panel", I created word.
Right demo works on webkit only, because it is for Smartphone.

Only Fixnel Demo

Download this project as a .zip file Download this project as a tar.gz file

What is Lorem Ipsum?

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.

It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).

Where does it come from?

Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.

The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from "de Finibus Bonorum et Malorum" by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham.

Syntax

Fixnel(element, [options]);

Options

{
direction: '[which direction]',
scrollbarColor: '[any color as CSS colors]',
scrollbarBdrColor: '[any color as CSS colors]',
scrollbarBdrRadius: [number]
}

directionには文字列で、['vertical' | 'horizontal' | 'both']のいずれかを指定するか、 Fixnel.directionType.[VERTICAL | HORIZONTAL | BOTH]のいずれかを指定します。 デフォルトは vertical です。
scroll****は、それぞれスクロールバーの色と丸みを設定します。背景が黒などの場合に色を指定することで視認性が上がります。

Options takes one object as argument. One of options is "direction". That is given a string. Whichever are ['vertical' | 'horizontal' | 'both']. You also can use Fixnel.directionType property. It contains [VERTICAL | HORIZONTAL | BOTH]. Default is "vertical".
scroll*** is scrollbar settings for color and radius. If you use Fixnel on the background color is black, you can apply any color to scrollbar.

Example

var ele = document.getElementById('[target ID]');

//only vertical
var fixnel = new Fixnel(ele);

//only horizontal
var fixnel = new Fixnel(ele, {
direction: Fixnel.directionType.HORIZONTAL
});

//both
var fixnel = new Fixnel(ele, {
direction: Fixnel.directionType.BOTH
});

Instance method

fixnel.moveTo(x, y[, opt]);

moveToメソッドは、指定されたx, yの座標に移動します。
もしオプションとして {animate: false} を指定すると、アニメーションなしで即座にその場に移動します。

fixnel move to [x, y].
If you give an opt, you can control moving. opt has one property. It is "animate". If you give it to "false", moveTo method move to [x, y] without animation.

fixnel.update();

update メソッドは高さが変更されたときに呼び出すことで、スクロール量などをアップデートします。
デフォルトでは window.resizeが 発火したタイミングで自動的に実行されるので、スマートフォンの回転時は自動でアップデートされます。
Ajaxなどでコンテンツの中身が動的に変化した場合などに呼び出してください。

update method give to control for contents height changing. If you update contents, you should call the update method. When window.resize was fired, fixnel called update automatically.

Events

/* Syntax: */
fixnel.on('moveendx', function() {...});

movestart[x, y], moveend[x, y], move[x, y]それぞれにイベントが発火されます。
moveイベントのみ、引数として {value: pos} データが渡されます。現在の移動量を返します。

Fixnel fire event each of movestart[x, y], moveend[x, y], move[x, y].
move event takes object ({value: pos}) as argument. It is value of moving amount.