Coder Social home page Coder Social logo

rocknrollmarc / angular-scroll-toggle Goto Github PK

View Code? Open in Web Editor NEW

This project forked from rcorrie/angular-scroll-toggle

0.0 1.0 0.0 156 KB

ScrollToggle abstracted into AngularJS directive

Home Page: http://hiyermedia.com/angular-scroll-toggle/

License: MIT License

CSS 16.27% HTML 83.73%

angular-scroll-toggle's Introduction

ScrollToggle

ScrollToggle is a small JavaScript component that lets you perform actions on elements depending on which direction the viewport is scrolled.

DEMO

How to use

Include the JS and CSS files, then inject the angular-scroll-toggle module into your app.

var myApp = angular.module('myApp', ['angular-scroll-toggle']);

Now you can apply the directive to any element.

<div scroll-toggle> This is my element! </div>

You can conditionally halt the directive by passing a boolean to the toggle-if scope attribute, as demonstrated below.

app.controller('myController', function($scope, $timeout){
	$scope.activateScrollToggle = false;
	$timeout(function(){
			$scope.activateScrollToggle = true;
	}, 5000);
});
<div scroll-toggle toggle-if="activateScrollToggle">...</div>

Callback

You can define your own callback function like so:

<div ng-controller="myController">
	<div scroll-toggle="myCallback">{{scroll.direction}}</div>
</div>
app.controller('myController', function($scope){
	$scope.scroll = {};
	$scope.scroll.direction;
	$scope.myCallback = function(direction, element){
		if(direction) $scope.scroll.direction = 'Down';
		else $scope.scroll.direction = 'Up';
	}
})

Option Attributes

You can add the following attributes to the element on which you applied the directive:

  • scrollClass applies passed class name to element on init

  • scrollUpClass applies passed class name to element on upwards scroll

  • scrollDownClass applies passed class name to element on downward scroll

  • offset ignores scrolling between top margin and offset

TODO

  • Add halt option
  • Accept callback functions

angular-scroll-toggle's People

Watchers

RocknrollMarc avatar

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.