Giter Club home page Giter Club logo

angular-sticky's Introduction

Build Status devDependency Status

Angular Sticky

Pure javascript AngularJS directive to make elements stick when scrolling

Demo

Do you want to see directives in action? Visit http://harm-less.github.io/angular-sticky

Installation

Requirements

  • AngularJS (requires AngularJS 1.4.x or higher, tested with 1.4.9)
  • Supports all major browsers and IE9 and up (lower versions might not be supported)

Install with Bower (recommended)

To install Angular Sticky with Bower use:

bower install angular-sticky-plugin

Or with npm

npm install angular-sticky-plugin

Manually

Click here to download the latest version of the plugin. In the dist folder you'll find the minified and normal JavaScript file. Either one is fine to use, it just depends on your needs.

Adding it to your project

As soon as you've got all the files downloaded and included in your page you just need to declare a dependency on the module:

angular.module('myModule', ['hl.sticky']);

Contributing to the project

We are always looking for quality contributions!

There are several useful Grunt tasks you can run in order to use/change the project:

  • serve: Use to demo application in order to develop the scripts from the js folder.
  • build: Build the files from the js folder to the dist folder

Note: If you make a pull-request, there is no need to build the project as this is done only for a new release.

Todo

  • Configurable z-index (preferably in each stack)
  • Media queries based on predefined breakpoints (e.g. min-width: lg-max) so the code is DRYer in combination with Bootstrap or other grid frameworks
  • There seems to be a weird bug were an element becoming sticky starts shaking a little
  • I strongly suspect that performance can be improved at various parts in the code. For example by caching more.

angular-sticky's People

Contributors

dotkev avatar harm-less avatar maciejklak avatar phazei avatar psaniko 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  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  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  avatar

angular-sticky's Issues

Placeholder causes the window to scroll-down when using ui-bootstrap's popover

Noticed this bug when opening a small popover when the sticky element (table header in my case) was sticky and the placeholder for the sticky element is completely out of view.

Bootstrap's popover causes a re-render of the sticky element, which cause the placeholder to be removed and re-added back, and a window scroll down (by the placeholder/sticky element's height).

Using the event change API we see that the the bootstrap poopover causes a change from stick to stick

<div hl-sticky event="stickyChanged(event)"></div>

function stickyChanged({event)}) {
  console.log(event); //prints stick every time the popover is opened
}

Diagnosed it with chrome dev-tools performance tab (browser render happens right after the sticky state render)
image


For people who get this bug too:

A fix we did was to counteract the scrolling side-effect was to scroll back that amount of pixels inside the event attribute provided with the API of the directive.

Something like:

function stickyChanged({event: stickyStatus}) {
  const scrollDiff = window.scrollY - <PLACEHOLDER_HEIGHT>;

  if (stickyStatus == 'stick' && lastStickyStatus == stickyStatus) {
    if (scrollDiff >= 50) {
      window.scrollBy(0, - <PLACEHOLDER_HEIGHT>); //should be negative in our case
    }
  }
  lastStickyStatus = stickyStatus;
}

Listen to touchmove events for mobile scroll

Thanks for this great plugin! We are currently trying to optimize for mobile devices and face the many challenges of mobile scrolling. A common kind-of-fix is to listen to touchmove events, maybe this could get an optional flag for the next release?

Replaces the element with a div

If You don't use a <div> as a element with the hl-sticky attribute it'll replace the element with it, so we can't use it with a ie. <section> element.

elementWidth()

function elementWidth() {
return container ? container.clientWidth : nativeEl.offsetWidth;
}

might be better

Enable redraw method for directive

Hi,
it would be nice if i could trigger redraw on the directive element manually when needed without having to use the hlStickyElement.

Installation instructions wrong

Hey, the library looks great, but I've been having a lot of trouble getting things working due to inaccurate docs. The bower install line should be bower install angular-sticky-plugin, currently it points to a totally different library. Also, to include it in the project it appears to be hl-sticky rather than hl.sticky. Finally, https://github.com/jonathantneal/angular-sticky shares the same name, which makes googling for this lib tricky. Not sure what you can do about that really, but FYI.

We cannot update bower

Ciao!

How are you?

We cannot angular-sticky, we get this error:

Unhandled rejection Error: Failed to execute "git ls-remote --tags --heads https://github.com/mattosborn/angular-sticky.git", exit code of #128
remote: Invalid username or password.
fatal: Authentication failed for 'https://github.com/mattosborn/angular-sticky.git/'

    at createError (/usr/lib/node_modules/bower/lib/util/createError.js:4:15)
    at ChildProcess.<anonymous> (/usr/lib/node_modules/bower/lib/util/cmd.js:102:21)
    at ChildProcess.emit (events.js:159:13)
    at maybeClose (internal/child_process.js:943:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:220:5)

"angular-sticky": "angular-sticky-plugin#^0.4.2"

Please publish new version to npmjs

Hey, thanks for this nice module.

Would you mind publishing the latest version (2.4) to npmjs.com?
Currently, version 1.1 is reported as latest version there:

2016-08-01 09_39_13-angular-sticky-plugin

Let me know if I can help you there.

Page Jumps on click

When using this plugin, the page jumps down about 50px when clicking any element (or body) once the container is "stuck".

Make Angular resolve to "~1.*"

In Bower.json make Angular resolve to "~1." so people with a higher Angular version than 1.4. can use it too.
Perhaps even set an range to recommend to people with lower versions to upgrade to 1.4 or higher.

Want it Sticky only after scrolling past other bottom elements

Love this plugin and I am using this in my Angular 1.5.9. and it works. However, I want to know if something like this possible.

I want the sticky element to become sticky only after the other bottom divs are scrolled. For example, I have a left side bar like this:

<div class="block-1 avatar" hl-sticky="" offset-top="50">
<!-- STICKY AVATAR -->
</div>
<div class="block-2 statistics">
<!-- SOME STUFF -->
</div>
<div class="block-3 comments">
<!-- SOME STUFF -->
</div>
<div class="block-4 recommendations">
<!-- SOME STUFF -->
</div>

At the moment, it is sticky from the moment the block-1 avatar is scrolled so it overlaps on the other bottom divs on scrolling.

What I want is, I want the above left bar divs to be relative during scroll and I only want the block-1 avatar to become sticky after the user has scrolled past block-4 recommendations.

I read the API and not sure if there is a setting for it. Is the above possible?

Thanks,
Neel.

prevent stacking of non-overlapping sticky elements?

I have two bootstrap columns both with sticky elements in them

<div class="col-md-6">
    <div hl-sticky="">
        left sticky
    </div>
</div>
<div class="col-md-6">
    <div hl-sticky="">
        right sticky
    </div>
</div>

they do not overlap and id like them to both stick to the top of the screen, the problem i am having is that the second (right) sticky, is offset in the Y position starting from the bottom of the left div, id like them both to sit flush at the top of the screen.

I have a work around of setting the offset-top of the right sticky to negative the left sticky height but it feels a bit hacky, what is the best way to achieve this? thanks

Angular 1.5.8

Does this plugin work in Angular 1.5.x? I can't seem to get it to work.

Sticky element position don't rerendred on resize

Hi.
I use this code for program usage of angular-sticky and add resize into events. resize events working, but sticky elemen not rerendered. Only after scroll it fix position:

angular.element($window).bind('scroll resize', function() {
	// draw the sticky element through an apply as the event wasn't from Angular
	$scope.$apply(function() {
		stickyElement.draw();
	});
});

Do you have some ideas what wrong?

bug with width

bad width after hide->show element (#element).
Problem with method (line 309):
function elementWidth() { return nativeEl.offsetWidth; }
because after hide this method set width to 0 and after show set always 0.

<div id="element" style="width: 200px;"> <div hl-sticky="" style="background-color: red"> Test </div> <div> <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br> 1 <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br> 2 <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br> </div> </div

use-placeholder false is incorrectly processed

I've noticed a bug with use-placeholder option. Neither of the following variants lead to usePlaceholder option to be false:

<div hl-sticky use-placeholder="false">
<div hl-sticky use-placeholder="{{false}}">

Instead options.usePlaceholder is equal to string value "false" that is evaluated as true in the code. It results in creating placeholder always independently of the option value.

Issues with Dynamic Content

I have a toolbar with anchor="bottom". The toolbar is located below a table that takes a few seconds to load. Before the table's data is loaded, the toolbar is rendered correctly, in the non sticky position. After the data is loaded and the table rows are rendered, the toolbar gets bumped down the page, out of view. The toolbar does not become sticky. Any recommendations?

layout breaks when using ng-show

When using ng-show on an element that also has hl-sticky my content appears fixed to the top left of the page upon ng-show being set to true. If i do not use ng-show then all works as expected and looks great

Support of position: sticky?

Are there any plans to support the upcoming specification of stickily positioned elements?

https://www.w3.org/TR/css-position-3/#sticky-pos

We realize this is quite early and not at all widely supported but we need smooth stickyness on iOS devices and are considering switching to fixed-sticky because of this. As this switch would come with a lot of drawbacks, we would like to know if such an implementation is on the horizon or even at all possible with the current approach.

stickyness of all elements is lost, if one element gets destroyed

We have several sticky elements. Some of them are included in view of states from the ui-router.
So if there is a state change, the destroy function of the sticky elements which are not available anymore is fired. But here the stickyness of all elements gets removed, even those which should stay sticky.

You should only destroy the 'hlSticky' Directive which fires the destroy function, not ALL!

$scope.$on('$destroy', function onDestroy() { stickyElementCollection.destroy(); });

Need help?

I volunteer to help maintain this project. Lmk.

Immediately show sticky-element (bottom)

Hey, I have a problem.

I want to show a button on the bottom of the page (sticky). When I scroll down the whole page (like 2000 px), then it should not be sticky anymore and be at its position. Everything works fine until now. The Problem is, the element shows just up, when I scroll. I tried to work with “always-sticky”, then it is visibly from the beginning, but it does not “unstick” at the bottom of the page. Is there a way, where I can tell the element to be visible right from the beginning? Without scrolling?

Cheers, Sean Roddis

Doesn't work with inner scrolling areas.

Unless I'm totally misreading the docs, there doesn't seem to be a way to make elements stick within a scrollable area that isn't the main area. That's probably a pretty important feature to a large group of people (including me).

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.