---
layout: "docs_api"
version: "unstable"
versionHref: "/docs/unstable"
path: "api/directive/faScrollView/"
title: "fa-scroll-view"
header_sub_title: "Directive in module famous.angular"
doc: "faScrollView"
docType: "directive"
---

<div class="improve-docs">
  <a href='https://github.com/Famous/famous-angular/edit/master/src/scripts/directives/fa-scrollview.js#L1'>
    Improve this doc
  </a>
</div>





<h1 class="api-title">

  fa-scroll-view



</h1>





This directive allows you to specify a <a href="https://famo.us/docs/views/Scrollview">famo.us Scrollview</a>
that will lay out a collection of renderables sequentially in the specified direction
and will allow you to scroll through them with mousewheel or touch events.






  
<h2 id="usage">Usage</h2>
  
```html
<fa-scroll-view>
  <fa-view>
    <!-- content -->
  </fa-view>
</fa-scroll-view>
```
  
  

  



<h2 id="example">Example</h2><h3 id="scroll-view-events-ng-repeat">Scroll View + Events + ng-repeat</h3>
<p>In the example below, <code>fa-scroll-view</code> displays a collection of nested <code>fa-views</code> generated by ng-repeat.
In Famous, events are not propagated from these nested <code>fa-view</code>&#39;s to its parent <code>fa-scroll-view</code>.</p>
<p>When a nested View needs to trigger higher-order app behavior within another View (such as a Scroll View), the best practice is to pass data via Famous Events.</p>
<p>To use a Scroll View, create an instance of a Famous Event Handler on the scope.  Within each ng-repeated <code>fa-view</code> are nested <code>fa-surface</code>s.  Pipe all Surface events to the event handler using <code>fa-pipe-to</code>, and then specify that the Scroll View will receive events from that specific event handler using <code>fa-pipe-from</code>.</p>
<p>Input events (like click or mousewheel) are captured on Surfaces, and piping must be used to specify where the events will broadcast and be received.
This will enable scrolling by connecting input events from the <code>fa-surface</code>s to the <code>fa-scroll-view</code>, otherwise the Scroll View will not receive mousewheel events.</p>
<p> 

{% assign lvl = page.url | append:'X' | split:'/' | size %}
{% capture relative %}{% for i in (3..lvl) %}../{% endfor %}{% endcapture %}

<div>
  <a ng-click="openPlunkr('{{ relative }}examples/example-example41')" class="btn pull-right">
    <i class="glyphicon glyphicon-edit">&nbsp;</i>
    Edit in Plunker</a>
  <div class="runnable-example" path="examples/example-example41"
      
        module="faScrollViewExampleApp"
      
  >

   
    <div ng-non-bindable class="runnable-example-file"
      
        name="index.html"
      
        language="html"
      
        type="html"
      
    >
      <pre><code>{% raw %}&lt;fa-app ng-controller=&quot;ScrollCtrl&quot;&gt;&#10;  &lt;!-- fa-scroll-view receives all events from $scope.myEventHandler, and decides how to handle them --&gt;&#10;  &lt;fa-scroll-view fa-pipe-from=&quot;myEventHandler&quot;&gt;&#10;      &lt;fa-view ng-repeat=&quot;view in views&quot;&gt;&#10;        &lt;fa-modifier fa-size=&quot;[undefined, 160]&quot;&gt;&#10;        &lt;!-- All events on fa-surfaces (click, mousewheel) are piped to $scope.myEventHandler --&gt;&#10;           &lt;fa-surface fa-background-color=&quot;view.color&quot;&#10;                        fa-pipe-to=&quot;myEventHandler&quot;&gt;&#10;           &lt;/fa-surface&gt;&#10;          &lt;/fa-modifier&gt;&#10;      &lt;/fa-view&gt;&#10;  &lt;/fa-scroll-view&gt;&#10;&lt;/fa-app&gt;&#10;&#10;&lt;script&gt;&#10;  angular.module(&#39;faScrollViewExampleApp&#39;, [&#39;famous.angular&#39;])&#10;      .controller(&#39;ScrollCtrl&#39;, [&#39;$scope&#39;, &#39;$famous&#39;, function($scope, $famous) {&#10;        &#10;        var EventHandler = $famous[&#39;famous/core/EventHandler&#39;];&#10;&#10;        $scope.views = [{color: &#39;red&#39;}, {color: &#39;blue&#39;}, {color: &#39;green&#39;}, {color: &#39;yellow&#39;}, {color: &#39;orange&#39;}];&#10;&#10;        $scope.myEventHandler = new EventHandler();&#10;&#10;    }]);&#10;&lt;/script&gt;{% endraw %}</code></pre>
    </div>
  
    <div ng-non-bindable class="runnable-example-file"
      
        name="style.css"
      
        language="css"
      
        type="css"
      
    >
      <pre><code>{% raw %}fa-app {&#10;  position: fixed;&#10;  top: 0;&#10;  right: 0;&#10;  bottom: 0;&#10;  left: 0;&#10;}{% endraw %}</code></pre>
    </div>
  

    <iframe class="runnable-example-frame" src="{{ relative }}examples/example-example41/index.html" name="example-example41"></iframe>
  </div>
</div>


</p>
<p>To specify (optional) configurable options for the Scroll View, bind an object on the scope to the <code>fa-options</code> attribute on <code>fa-scroll-view</code>.
Notable options include <code>clipSize</code>, which specifies the size of the area in pixels to display content in, and <code>direction</code>, which specifies whether the nested views will scroll horizontally or vertically (1 is vertical, 0 is horizontal).
A full list of configurable options for Scroll View may be found at <a href="https://famo.us/docs/0.2.0/views/Scrollview/">https://famo.us/docs/0.2.0/views/Scrollview/</a>.</p>
<p> 

{% assign lvl = page.url | append:'X' | split:'/' | size %}
{% capture relative %}{% for i in (3..lvl) %}../{% endfor %}{% endcapture %}

<div>
  <a ng-click="openPlunkr('{{ relative }}examples/example-example42')" class="btn pull-right">
    <i class="glyphicon glyphicon-edit">&nbsp;</i>
    Edit in Plunker</a>
  <div class="runnable-example" path="examples/example-example42"
      
        module="faScrollViewExampleApp"
      
  >

   
    <div ng-non-bindable class="runnable-example-file"
      
        name="index.html"
      
        language="html"
      
        type="html"
      
    >
      <pre><code>{% raw %}&lt;fa-app ng-controller=&quot;ScrollCtrl&quot;&gt;&#10;  &lt;fa-scroll-view fa-pipe-from=&quot;myEventHandler&quot; fa-options=&quot;options.myScrollView&quot;&gt;&#10;      &lt;fa-view ng-repeat=&quot;view in list&quot;&gt;&#10;        &lt;fa-modifier fa-size=&quot;[500, 320]&quot;&gt;&#10;           &lt;fa-surface fa-background-color=&quot;view.color&quot;&#10;                        fa-pipe-to=&quot;myEventHandler&quot;&gt;&#10;              {{view.content}}&#10;           &lt;/fa-surface&gt;&#10;          &lt;/fa-modifier&gt;&#10;      &lt;/fa-view&gt;&#10;  &lt;/fa-scroll-view&gt;&#10;&lt;/fa-app&gt;&#10;&#10;&lt;script&gt;&#10;  angular.module(&#39;faScrollViewExampleApp&#39;, [&#39;famous.angular&#39;])&#10;      .controller(&#39;ScrollCtrl&#39;, [&#39;$scope&#39;, &#39;$famous&#39;, function($scope, $famous) {&#10;        &#10;        var EventHandler = $famous[&#39;famous/core/EventHandler&#39;];&#10;        $scope.myEventHandler = new EventHandler();&#10;        $scope.list = [{content: &quot;Scroll&quot;, color: &quot;red&quot;}, {content: &quot;horizontally&quot;, color: &quot;blue&quot;}, {content: &quot;yay!&quot;, color: &quot;green&quot;}, {content: &quot;woo!&quot;, color: &quot;yellow&quot;}];&#10;        &#10;        $scope.options = {&#10;          myScrollView: {&#10;            clipSize: 100,&#10;            paginated: false,&#10;            speedLimit: 5,&#10;            direction: 0,&#10;          }&#10;        };&#10;&#10;    }]);&#10;&lt;/script&gt;{% endraw %}</code></pre>
    </div>
  
    <div ng-non-bindable class="runnable-example-file"
      
        name="style.css"
      
        language="css"
      
        type="css"
      
    >
      <pre><code>{% raw %}fa-app {&#10;  position: fixed;&#10;  top: 0;&#10;  right: 0;&#10;  bottom: 0;&#10;  left: 0;&#10;}{% endraw %}</code></pre>
    </div>
  

    <iframe class="runnable-example-frame" src="{{ relative }}examples/example-example42/index.html" name="example-example42"></iframe>
  </div>
</div>


</p>
<h3 id="scroll-view-with-explicitly-created-views">Scroll View with explicitly created views</h3>
<p><code>Fa-index</code> determines the order of which the surfaces appear in the sequential view.
In this example below, a Scroll View is created with two nested <code>fa-view</code>&#39;s, both of which have an <code>fa-index</code> of 0 and 1, respectively.</p>
<p>If <code>fa-index</code> is declared explicitly, it will override any default order of <code>fa-view</code>&#39;s declared in html.
If <code>fa-views</code> are created with an ng-repeat, they are automatically assigned the $index property, unless explicitly set.
The <code>fa-view</code> with the blue background color appears after the one with the red background because its <code>fa-index</code> is set to 1.</p>
<p><code>fa-scroll-view</code> accepts another attribute called <code>fa-start-index</code>, which determines which <code>fa-view</code> the Scroll View displays by default.
<code>Fa-start-index</code> will not affect the sequential order of the layout; the <code>fa-view</code> with the red background will be layed out first, followed by the one with the blue background.
By setting <code>fa-start-index</code> to 1, the Scroll View will display the View with the index of 1 by default, &quot;starting&quot; at the index of 1, which is the View with the blue background color.</p>
<p> 

{% assign lvl = page.url | append:'X' | split:'/' | size %}
{% capture relative %}{% for i in (3..lvl) %}../{% endfor %}{% endcapture %}

<div>
  <a ng-click="openPlunkr('{{ relative }}examples/example-example43')" class="btn pull-right">
    <i class="glyphicon glyphicon-edit">&nbsp;</i>
    Edit in Plunker</a>
  <div class="runnable-example" path="examples/example-example43"
      
        module="faScrollViewExampleApp"
      
  >

   
    <div ng-non-bindable class="runnable-example-file"
      
        name="index.html"
      
        language="html"
      
        type="html"
      
    >
      <pre><code>{% raw %}&lt;fa-app ng-controller=&quot;ScrollCtrl&quot; style=&quot;width: 100%; height: 320px; overflow: hidden;&quot;&gt;&#10;  &lt;!-- The scroll View will start at the index of 1 --&gt;&#10;   &lt;fa-scroll-view fa-pipe-from=&quot;eventHandler&quot; fa-options=&quot;options.scrollViewTwo&quot; fa-start-index=&quot;1&quot;&gt;&#10;     &lt;!-- Even though this view is declared first in html, it will will be layed out 2nd --&gt;&#10;     &lt;!-- On page load, the scroll View will scroll to this view, and display it.  --&gt;&#10;      &lt;fa-view fa-index=&quot;1&quot;&gt;&#10;         &lt;fa-modifier fa-size=&quot;[undefined, 320]&quot;&gt;&#10;            &lt;fa-surface fa-pipe-to=&quot;eventHandler&quot;&#10;                        fa-background-color=&quot;&#39;blue&#39;&quot;&gt;&#10;              I am first in html, but displayed second!&#10;            &lt;/fa-surface&gt;&#10;         &lt;/fa-modifier&gt;&#10;      &lt;/fa-view&gt;&#10;&#10;      &lt;fa-view fa-index=&quot;0&quot;&gt;&#10;         &lt;fa-modifier fa-size=&quot;[undefined, 320]&quot;&gt;&#10;            &lt;fa-surface fa-pipe-to=&quot;eventHandler&quot;&#10;                        fa-background-color=&quot;&#39;red&#39;&quot;&gt;&#10;              I am second in html, but displayed first!  Scroll horizontally!&#10;            &lt;/fa-surface&gt;&#10;         &lt;/fa-modifier&gt;&#10;      &lt;/fa-view&gt;&#10;&#10;   &lt;/fa-scroll-view&gt;&#10;&lt;/fa-app&gt;&#10;&#10;&lt;script&gt;&#10;  angular.module(&#39;faScrollViewExampleApp&#39;, [&#39;famous.angular&#39;])&#10;      .controller(&#39;ScrollCtrl&#39;, [&#39;$scope&#39;, &#39;$famous&#39;, function($scope, $famous) {&#10;        &#10;        var EventHandler = $famous[&#39;famous/core/EventHandler&#39;];&#10;        $scope.eventHandler = new EventHandler();&#10;        $scope.list = [{content: &quot;famous&quot;}, {content: &quot;angular&quot;}, {content: &quot;rocks!&quot;}];&#10;        &#10;        $scope.options = {&#10;          scrollViewTwo: {&#10;            direction: 0,&#10;            paginated: true&#10;          }&#10;        };&#10;&#10;    }]);&#10;&lt;/script&gt;{% endraw %}</code></pre>
    </div>
  

    <iframe class="runnable-example-frame" src="{{ relative }}examples/example-example43/index.html" name="example-example43"></iframe>
  </div>
</div>


</p>
<h3 id="combining-multiple-scroll-views">Combining multiple Scroll Views</h3>
<p>Combining both approaches above (a Scroll View with ng-repeated views, and one with explicitly created views), one can can nest a Scroll View within another Scroll View.
A Scroll View is a Famous widget that displays a collection of views sequentially; it is agnostic about the Views that are inside of it; it only requires that events are piped from Surfaces to the ScrollView.</p>
<p>In the example below, the outer Scroll View contains two explictly created Views.  One of those Views contains another Scroll View with sub-views created through an ngRepeat.
The outer Scroll View is passed an option for its <code>direction</code> to be <code>horizontal (0)</code>, and the inner Scroll View is passed an option for a <code>vertical direction (1)</code>.</p>
<p> 

{% assign lvl = page.url | append:'X' | split:'/' | size %}
{% capture relative %}{% for i in (3..lvl) %}../{% endfor %}{% endcapture %}

<div>
  <a ng-click="openPlunkr('{{ relative }}examples/example-example44')" class="btn pull-right">
    <i class="glyphicon glyphicon-edit">&nbsp;</i>
    Edit in Plunker</a>
  <div class="runnable-example" path="examples/example-example44"
      
        module="faScrollViewExampleApp"
      
  >

   
    <div ng-non-bindable class="runnable-example-file"
      
        name="index.html"
      
        language="html"
      
        type="html"
      
    >
      <pre><code>{% raw %}&lt;fa-app ng-controller=&quot;ScrollCtrl&quot; style=&quot;width: 100%; height: 568px;&quot;&gt;&#10;  &lt;!-- outer scroll view that scrolls horizontally between &quot;main&quot; view and &quot;sidebar&quot; view--&gt;&#10;  &lt;fa-scroll-view fa-pipe-from=&quot;eventHandler&quot; fa-options=&quot;options.scrollViewOuter&quot;&gt;&#10;&#10;    &lt;!-- sidebar view --&gt;&#10;    &lt;fa-view fa-index=&quot;0&quot;&gt;&#10;      &lt;fa-modifier fa-size=&quot;[200, undefined]&quot; id=&quot;sideBarMod&quot;&gt;&#10;          &lt;fa-surface fa-pipe-to=&quot;eventHandler&quot;&#10;                      fa-background-color=&quot;&#39;blue&#39;&quot;&#10;                      fa-size=&quot;[undefined, undefined]&quot;&gt;&#10;            Sidebar (scroll horizontally to hide)&#10;          &lt;/fa-surface&gt;&#10;        &lt;/fa-modifier&gt;&#10;    &lt;/fa-view&gt;&#10;&#10;    &lt;!-- main view --&gt;&#10;    &lt;fa-view fa-index=&quot;1&quot;&gt;&#10;    &lt;!-- inner scroll view that scrolls vertically--&gt;&#10;      &lt;fa-scroll-view fa-pipe-from=&quot;eventHandler&quot; fa-options=&quot;options.scrollViewInner&quot;&gt;&#10;        &lt;fa-view ng-repeat=&quot;item in list&quot;&gt;&#10;          &lt;fa-surface fa-pipe-to=&quot;eventHandler&quot;&#10;                      fa-size=&quot;[undefined, 200]&quot;&#10;                      fa-background-color=&quot;&#39;red&#39;&quot;&gt;&#10;            {{item.content}}&#10;          &lt;/fa-surface&gt;&#10;        &lt;/fa-view&gt;&#10;      &lt;/fa-scroll-view&gt;&#10;    &lt;/fa-view&gt;&#10;&#10;  &lt;/fa-scroll-view&gt;&#10;&lt;/fa-app&gt;&#10;&#10;&lt;script&gt;&#10;  angular.module(&#39;faScrollViewExampleApp&#39;, [&#39;famous.angular&#39;])&#10;      .controller(&#39;ScrollCtrl&#39;, [&#39;$scope&#39;, &#39;$famous&#39;, function($scope, $famous) {&#10;        &#10;        var EventHandler = $famous[&#39;famous/core/EventHandler&#39;];&#10;        $scope.eventHandler = new EventHandler();&#10;        $scope.list = [{&#10;          content: &quot;Awesome content&quot;&#10;        },{&#10;          content: &quot;Scroll vertically to see more awesome content&quot;&#10;        },{&#10;          content: &quot;Famo.us/angular rocks!&quot;&#10;          }&#10;        ];&#10;        &#10;        $scope.options = {&#10;          scrollViewOuter: {&#10;            direction: 0,&#10;            paginated: true&#10;          },&#10;          scrollViewInner :{&#10;            direction: 1&#10;          }&#10;        };&#10;&#10;    }]);&#10;&lt;/script&gt;{% endraw %}</code></pre>
    </div>
  

    <iframe class="runnable-example-frame" src="{{ relative }}examples/example-example44/index.html" name="example-example44"></iframe>
  </div>
</div>


</p>



