Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image floating from left #5

Open
levipadre opened this issue Jun 6, 2015 · 5 comments
Open

Image floating from left #5

levipadre opened this issue Jun 6, 2015 · 5 comments

Comments

@levipadre
Copy link

Hi,

I just stared to use this directive. It seems really good, just I can't figure it out, how can I float one of my images.
Basically, when the user is scrolling, the image starts the float from out of the screen on the left side, and finally arrives the original point.
I tried with this:

scroll-watch="{from: 1000, to: -1}" sw-style="{left: 100 * $progress + '%'}"

but the direction is wrong, and now is going to right from the starting point.
Do you know where is the problem?

@levipadre levipadre changed the title Float from left Image floating from left Jun 6, 2015
@levipadre
Copy link
Author

Also I don't want to see to disappear, when I'm scrolling up again. Is that possible?

@pc035860
Copy link
Owner

pc035860 commented Jun 7, 2015

Hi @levipadre ,

Try

scroll-watch="{from: 1000, to: -1}" sw-style="{left: 100 * (1-$progress) + '%'}"

@levipadre
Copy link
Author

Hi,

Thank you, it's working.

@levipadre
Copy link
Author

And do you know that possible to stop the reverse watching? I don't want to move back my element.
With class is also good for me, like this:

scroll-watch="{from: 0, to: -1}" sw-class="{active: $percentage > 80 }"

Just when I scroll up, I need to keep the class

Also when I refresh the page, and I'm already there (80%), I need to scroll up and down again to get the class.

@pc035860
Copy link
Owner

pc035860 commented Jun 7, 2015

Hi @levipadre ,

I think you'll have to setup a scroll-broadcast to change a scope variable indicating that your element is in position.

It's kind of similar to #4.

scroll-watch="{from: 1000, to: -1}"
  sw-style="{left: animateLeft($progress) + '%'}"
  sw-broadcast="{
    'hiiiiiit': '$negative > -2'
  }"

And you can setup an scope method for your sw-style:

$scope.animateLeft = function (progress) {
  if ($scope.animated) {
    return 100;
  }
  return 100 * (1 - progress);
};

$scope.$on('hiiiiiit', function ($event, active) {
  if (active) {
    $scope.animated = true;
  }
});

It feels like a workaround though, one way to make this easier may be introducing some new directive like scroll-watch-once.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants