GithubHelp home page GithubHelp logo

cwadrupldijjit / ng2-parallax Goto Github PK

View Code? Open in Web Editor NEW
29.0 5.0 18.0 1.98 MB

A parallax plugin/directive for Angular 2. Learn more at:

Home Page: http://cwadrupldijjit.com/ng2-parallax

License: MIT License

JavaScript 59.08% TypeScript 40.92%

ng2-parallax's Introduction

ng2-parallax

A parallax plugin/directive for Angular 2

You can use this directive right now if you write Angular 2 code using SystemJS to import/export files, or at the very least you write it in Typescript. ES5 and Dart versions are not yet complete/started, but as demand grows for those as well as the documentation gets updated, those versions will be made available.

Installation of files

In order to install this plugin, you can do one of a few things:

  • Install from npm:
npm install --save ng2-parallax
  • clone it from the project GitHub repository:
git clone https://github.com/cwadrupldijjit/ng2-parallax

If you'd like to contribute, feel free to fork it.

If you have copied/created a version of the directive file (either parallax.directive.ts or parallax.directive.js), place the copy of the file in a convenient place to reference it in your working directory, and reference however you need to have it be available in the rest of your application.

To reference it in your application, you can import it just like the rest of the Angular files and components.

Using the npm package:

For System.js Users:

First, you have to register where the ng2-parallax is:

<!-- index.html -->
<script>
    System.config({
        paths: {
            '/*': '/app/*',
            'ng2-parallax/*': '/node_modules/ng2-parallax/*' // <--- add this
        },
        packages: {
            app: {
                format: 'register',
                defaultExtension: 'js'
            },
            '/node_modules/ng2-parallax': { // <--- and this
                format: 'register',
                defaultExtension: js
            }
        }
    });
    
    System.import('/app/boot')
        .then(null, console.error.bind(console));
</script>

For webpack Users:

NOTE: Webpack isn't as straightforward as I'd assume with requiring node_modules such as the ng2-parallax, and as such, despite my efforts in figuring out what is preventing it from reading from node_modules, I've been unable to locate the source of the problem. The direction below is just a temporary fix before we can get the situation straight with that one. Any help to get that working fine with webpack would be greatly appreciated.

If you have npm install-ed the parallax directive, you will have to either figure out how to reference it without problems, or you could simply copy it into a subdirectory of your app or src folder where it's easily accessible, then follow the import directions in the "Using a local copy" section below.

And then you can import it just like the Angular 2 components:

import { Component,
         View } from 'angular2/core';
import { Parallax,
        // either (for Systemjs)
         ParallaxConfig } from 'ng2-parallax/system';
        // or, if webpack is finding it fine:
         ParallaxConfig } from 'ng2-parallax/commonjs';

Using a local copy:

import { Component,
         View } from 'angular2/core';
import { Parallax,
         ParallaxConfig } from './path/to/directives/parallax.directive';

If you import both Parallax and ParallaxConfig, you can get some IntelliSense or type verification help for the parallaxConfig object you can define in your component's class. You'll see how to implement that shortly.

In order to get your component to recognize it, you need to add it to your component's annotations like so:

@Component({
    selector: 'my-app',
    templateUrl: `./path/to/template.html`,
    directives: [
        Parallax  // <----- Right here
    ]
})

Or:

@Component({
    selector: 'my-app'
})
@View({
    templateUrl: `./path/to/template.html`,
    directives: [
        Parallax  // <----- Right here
    ]
})
class MyComponent {}

You can then use the directive anywhere within that component itself by sticking it on any element you've put in your template like so:

<h1>Welcome to my website!</h1>

<div parallax></div>
<!-- ^ here ^ -->

This plugin assumes you've added styling to the element you've put the "parallax" attribute onto, like height, width, and background-image. If you'd like to override any of the default settings for the parallax directive when you'd like to customize the functionality. One way you can do that is by passing in a [config] object through the HTML.

<div parallax [config]="{parallaxInitVal: -100, parallaxRatio: .7}"></div>

For more specific information, refer to the examples found at the project page, or in the examples folder for the version of the plugin you'd like to use, which you can access when you've cloned or downloaded the project. Currently, only the TypeScript version works. The JS version is under development and the Dart version will happen later, when demand is up for it (or when it's requested and I have time to learn Dart or someone helps to contribute to that version... :P).

Any feedback is much appreciated. Log issues, send pull requests, you know the drill.

Thanks for showing interest in this project and hope you enjoy it!

ng2-parallax's People

Contributors

cwadrupldijjit avatar murhafsousli 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

Watchers

 avatar  avatar  avatar  avatar  avatar

ng2-parallax's Issues

Wrong config params on the documentation (Readme.md)

I just spend a while trying to make this library to work until I checked the actual directive and noticed that the config params are different from the ones on the documentation. I.E. the 'parallaxInitVal' is renamed to 'initialValue'. Could you change that for future references?

App Module works just fine with angular-cli

Hey there, I am installing this on a new angular-cli project, and I had to use the app module to load this. It seems to be loading fine, and webpack has no issue. Just thought you should know!

import { Parallax,
         ParallaxConfig } from 'ng2-parallax/commonjs';
@NgModule({
  declarations: [
    AppComponent,
    Parallax
  ]
  ...
})
export class AppModule { }

System is not defined exception

Hi, I'm trying to use parallax directive in angular2-webpack-starter, and I'm getting this exception:

Uncaught ReferenceError: System is not defined - parallax-ts:1

here is the code:

import { Component } from 'angular2/core';
import { Parallax, ParallaxConfig } from 'ng2-parallax/parallax-ts';

@Component({
  selector: 'post',
  template: `
<md-card>
  <img *ngIf="post.featuredImage" parallax [src]="post.featuredImage" class="md-card-image">
  <md-card-title>
    <md-card-title-text>
      <span class="md-headline">{{post.title.rendered}}</span>
    </md-card-title-text>
  </md-card-title>
  <md-card-content [innerHTML]="post.excerpt.rendered">
  </md-card-content>
</md-card>
`,
  styles: [require('./post.css')],
  directives: [Parallax]
})
export class PostCmp {
  constructor() {
  }
}

Thank you

Not working in rc1

Hi .. is there any plans for an update, it's not working with the latest rc1, thank you

Workflow to publish js files

hi @cwadrupldijjit, I'm using a new workflow to publish angular packages to npm as pre compiled js with ngc, which supports AOT.
If you would like to ship js files to npm, I can create a pull request for the gulpfile.js and then the steps are straight forward:

1 - increment package version
2 - build with gulp

gulp build 

3 - publish dist to npm

npm publish ./dist

Broken link with examples

The link of the page with examples is broken and cannot be reached.
Could you provide another link, please?

Looks aweful when applied to multiple elements created with *ngFor

It looks like directive applies background-position regardless element is in viewport, or not. This gives us an inconsistent look, and effect of multiple frames, stacked on each other (if background-repeat is default), or simply a white space (if background-repeat: no-repeat).

Is it possible to specify, that parallax should be applied taking element's offset from top into account? To not apply monstrous background-position of +200% etc?

Can't get it to work in Ionic3

Hi,

I'm using Ionic3 (wich uses Angular4). Fore some reason the backgrounds are just like normal backgrounds there, no parallax effect. In a normal Angular project this is working fine.. It must be some kind of css overriding that ionic does.

Have you got any idea?

Thanks!

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.