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
Feature: Using a service from inside a component to scroll #10
Comments
Basically this is the code I want to replace: let dialogElement = $(".dialog-content-for-scroll");
dialogElement.delay(700)
.animate({
scrollTop: this.state.scrollPosition
},
"slow");
dialogElement.on("scroll", () => {
this.state.scrollPosition = dialogElement.scrollTop();
this.sharedStorageService.set(OsmUserDialogComponent.OSM_USER_DIALOG_STATE_KEY, this.state);
}); |
Good point, scroll events are definitely a missing feature as of this moment. I'll create a seperate issue for implementation of scroll events. To stay in line with the way Angular Animation Callbacks work, I was thinking of the following set of events: 1. Start 2. End 3. Cancel Please note that the 3rd option has to do with this feature. The interface ScrollToEventData {
position: {
fixed: number;
dynamic: number;
}
} The difference in Please let know what you think and if this is applicable to your situation! Thanks |
I'm not sure I understand how this solves my issue - are these events generated from html that has a scroll-to directive on it? ctor(private scrollToService: ScrollToService) {
this.scrollToService.scrollToPosition(element, offset);
} |
Ah I see. I had my solution mostly based on this line you wrote:
Sorry for misunderstanding your question. I think you're solution to trigger scrolling from within a component is also a missing feature. I'll give this a go soon and give you a heads up when implemented. |
I see, the main intensive here is that I removed all references of JQuery from my code and it seems angular doesn't have a good solution for smooth scrolling so I was looking for a solution as since it seems you are actively maintaining this library I thought it could be a good fit for a feature suggestion. |
Cool, I'll keep you posted! We want those animations, right! 😄 |
- Needed for #10 to be able to trigger scrolls from insde a service (a.k.a. skipping Directive)
@HarelM This feature has been added to a new release. Please check the related section in the README.md for using an Angular Service for usage examples. Please let me know if your issue has been resolved or if you encounter any problems. Thanks! |
Thanks for the fast implementation!
|
@HarelM Good questions. Allow me to explain:
That won't work. The event is coming from the HTML Element that fires the event. This HTML Element is needed to calculate the first scrollable parent. Without it, the plugin won't be able to find a scroll container (for now!). There is already an issue open to specify a custom scroll container, see the issue here, so this will be available in the near future. Because this is a somewhat different issue, I've created a seperate bug for this, see bug here.
I'm not sure I understand correctly, but I think a const config: ScrollToConfig = {
target: 'destination',
offset: 100
}
This is already answered in question 1. A custom scroll-container will be added in the near future, so hold on tight! Thanks again for your issue submittance! |
Thanks for your prompt response! // this is called when a dialog is opened using the ngAfterViewInit- there's no clear event here to use.
let dialogElement = $(".dialog-content-for-scroll"); // this is the element I want to scroll, I can provide ElementRef if the ScrollTo API would accept it.
dialogElement.delay(700)
.animate({
scrollTop: this.state.scrollPosition // I don't want to scroll to another element but rather to a position offset in "dialogElement"
},
"slow");
dialogElement.on("scroll", () => {
this.state.scrollPosition = dialogElement.scrollTop(); // this is used to get the current position when this dialog scrolls so that next time I open it, it will open in the same scroll position.
this.sharedStorageService.set(OsmUserDialogComponent.OSM_USER_DIALOG_STATE_KEY, this.state);
}); So as far as I can tell, this implementation still doesn't cover my needs, so I'll wait for the other issues to be resolved and I'll try again. Here's my current implementation without JQuery: class SomeComponenet {
...
@ViewChild("dialogContentForScroll") dialogContent: ElementRef;
...
public ngOnInit() {
...
let dialogElement = this.dialogContent.nativeElement as HTMLElement;
// the following is the code I want to replace with a service:
setTimeout(() => dialogElement.scrollTop = this.state.scrollPosition, 700);
// end, below code is fine as is.
dialogElement.onscroll = () => {
this.state.scrollPosition = dialogElement.scrollTop;
this.sharedStorageService.set(OsmUserDialogComponent.OSM_USER_DIALOG_STATE_KEY, this.state);
}
... |
I see, great thing you've provided the snippets. Do you mind putting these into a separate issue? Thanks a bunch, looking forward for the implementation! |
See issue #28. |
I couldn't find it in the documentations - I would like to achieve the following:
I have a component that is a pop-up, and I want to scroll to the same location the user left it when it was closed.
So I need two functionalities
Currently I'm using JQuery. I would like to remove this dependency if possible and I thought this library might do the trick.
I also looked at smoothscroll-polyfill but I'm not sure it will do what I need.
Thoughts are appreciated.
The text was updated successfully, but these errors were encountered: