Giter VIP home page Giter VIP logo

ng-go-top-button's Introduction

ng-go-top-button

A simple customizable go-top button component for Angular projects.

Versions

This is the new version of the original ng2-go-top-button. This version was re-created according to the new Angular library format to support Angular v9 and higher. For previous Angular versions refer to the original version.

Installation

npm install ng-go-top-button --save

Usage

Import statement in the app module:

import {GoTopButtonModule} from 'ng-go-top-button';
import {BrowserAnimationsModule} from '@angular/platform-browser/animations';

...

@NgModule({
    ...
    imports: [..., GoTopButtonModule, BrowserAnimationsModule],
    ...

In the target app component:

import { Component, ViewEncapsulation } from '@angular/core';

@Component({
  ...
  encapsulation: ViewEncapsulation.None // for animations and custom styling to work
})
export class AppComponent {
...
}

On your template paste the <ng-go-top-button></ng-go-top-button> html. This will add a simple button with default styles and without animated scroll. By default go-top-button will appear on the right side, 50% top and bottom and without any icons or text. You can then customize its styles and behaviour.

Example of customization:

<ng-go-top-button 
                 [animate]="true"
                 [speed]="50"
                 [acceleration]="2"
                 [scrollDistance]="300"
                 [classNames]="'custom-class'"
                 [styles]="{
                    'border-radius': '20px 20px 20px 20px',
                    'right': '5px',
                    'color': 'green',
                    'border': '5px solid',
                    'line-height': '20px'
                 }">
        <i class=\'fa fa-arrow-up\'></i>
  </ng-go-top-button>

Custom CSS class declaration (if needed):

.custom-class {
    position: fixed;
    background-color: pink;
    border-color: green;
    height: 30px;
    width: 30px;
}

API

Property Type Description
scrollDistance number Number of pixels to be scrolled Y for button to be shown. Defaults to 200px. Must be greater than zero.
styles object User-defined styles config for the button.
classNames string Custom class names in the following format 'class1 class2 class3'. Note: this attribute completely overrides the default '.go-top-button' class attributes, so one should specify all style properties manually.
animate boolean If true, scrolling will be animated. False by default.
speed number Speed of animated scroll. Must be greater than 1. 80 by default.
acceleration number Number of pixels to speed up when scrolling is animated. 0 by default - this way page will be scrolled top with the constant speed.
tabIndex number Custom tabindex button attribute value, by default 0.

IE-specific issues:

IE does not support web animations. If you would like to enable them, install and import the corresponding polyfill to your polyfills.js file:

In your project's directory:

npm install --save web-animations-js

In polyfills.js:

import 'web-animations-js';

Example project

You can find example project that uses ng-go-top-button in projects/example-app/ directory of this repository. To run the example project execute the following commands from the root directory of the project:

ng build --project=example-app
cd projects/example-app
ng serve

ng-go-top-button's People

Contributors

annapogorelova avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

ng-go-top-button's Issues

support Angular 10

Hello,

there is a npm warning on installation of the modules when using Angular 10.0.4.

It works fine, so its only a cosmetic warning, but would be good to update the package.json of the library allowing that version of angular

image

Thanks

Package "ng-go-top-button" has an incompatible peer dependency

Could not update project from 12.1.1 to 12.1.2 with ng update @angular/cli @angular/core .

I'm guessing this will also happen if I attempt to download the library from a 12.1.2 angular project.

Package "ng-go-top-button" has an incompatible peer dependency to "@angular/animations" (requires "^10.2.1" (extended), would install "12.1.2").
Package "ng-go-top-button" has an incompatible peer dependency to "@angular/common" (requires "^10.2.1" (extended), would install "12.1.2").
Package "ng-go-top-button" has an incompatible peer dependency to "@angular/core" (requires "^10.2.1" (extended), would install "12.1.2").
Package "ng-go-top-button" has an incompatible peer dependency to "@angular/platform-browser" (requires "^10.2.1" (extended), would install "12.1.2").


ร— Migration failed: Incompatible peer dependencies found.
Peer dependency warnings when installing dependencies means that those dependencies might not work correctly together.
You can use the '--force' option to ignore incompatible peer dependencies and instead address these warnings later.
See "...\angular-errors.log" for further details.

I didn't want to use the force as mentioned lest I break the app.

issue while using ng migrate from angular 12 to angular 13

Hello Anna,

was trying to upgrade ng

ng update @angular-eslint/schematics @angular/cdk @angular/core @ngrx/store

and has the following error:

Package "ng-go-top-button" has an incompatible peer dependency to "@angular/animations" (requires "^10.2.1" (extended), would install "13.1.0")

could you please redefine the peer dependency so that no warnings comes ?

Thanks a lot

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.