Can I use this library with angular 4 framework ? #352
-
Can I use this library with angular 4 framework ? I 've tried this but nothing happens import { Component, OnInit, AfterViewInit } from '@angular/core';
import Scrollbar from "smooth-scrollbar";
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit, AfterViewInit {
title = 'app works!';
ngOnInit() {
console.log(Scrollbar);
}
ngAfterViewInit() {
const elem = document.createElement("div");
const scrollbar = Scrollbar.init(elem, {
continuousScrolling: true,
damping: 5,
overscrollDamping: 5,
overscrollEffect: "glow",
overscrollEffectColor: "green",
renderByPixels: true,
speed: 1,
syncCallbacks: true,
thumbMinSize: 1
});
Scrollbar.has(elem);
Scrollbar.get(elem) === scrollbar;
scrollbar.targets.container;
scrollbar.targets.xAxis.track;
scrollbar.update(true);
scrollbar.setPosition(10, 10);
scrollbar.addListener(status => status.direction);
scrollbar.infiniteScroll(status => status.direction.y);
scrollbar.hideTrack("both");
scrollbar.showTrack("x");
scrollbar.destroy(true);
}
} html file <div id="my-scrollbar" >
<p>test</p>
<p>test</p>
<p>test</p>
<p>test</p>
<p>test</p>
<p>test</p>
<p>test</p>
<p>test</p>
<p>test</p>
<p>test</p>
<p>test</p>
<p>test</p>
<p>test</p>
<p>test</p>
<p>test</p>
<p>test</p>
<p>test</p>
<p>test</p>
<p>test</p>
<p>test</p>
<p>test</p>
<p>test</p>
<p>test</p>
<p>test</p>
<p>test</p>
<p>test</p>
<p>test</p>
<p>test</p>
<p>test</p>
<p>test</p>
<p>test</p>
<p>test</p>
<p>test</p>
<p>test</p>
<p>test</p>
<p>test</p>
<p>test</p>
</div> any suggestion ? |
Beta Was this translation helpful? Give feedback.
Replies: 9 comments
-
I think you should init scrollbar on an element that already exists in the document, try: const elem = document.querySelector("#my-elem");
Scrollbar.init(elem); |
Beta Was this translation helpful? Give feedback.
-
I 've tried that but it doesn't work :( |
Beta Was this translation helpful? Give feedback.
-
I'm not familiar with angular4, can you provide a link to the repository so that I can test it myself? |
Beta Was this translation helpful? Give feedback.
-
https://github.com/rainstormza/ng4smoothscroll this is my reposotory. smoothscroll\src\app\app.component.ts you can implement with two of these files ps. before test project you might be install these package thanks for your help :) |
Beta Was this translation helpful? Give feedback.
-
Thanks. Will have a look. |
Beta Was this translation helpful? Give feedback.
-
@rainstormza hey dude, your problem is not about the initialization of scrollbar, you should give an explicit size to the container element, for example: #my-scrollbar {
height: 500px;
width: 500px;
} You can refer to common mistakes section for more information :) |
Beta Was this translation helpful? Give feedback.
-
it works @idiotWu |
Beta Was this translation helpful? Give feedback.
-
What version of typescript does smooth-scrollbar support? I keep getting this error - |
Beta Was this translation helpful? Give feedback.
-
@yohanelly95 this project was developed under typescript 3.6.3. |
Beta Was this translation helpful? Give feedback.
@rainstormza hey dude, your problem is not about the initialization of scrollbar, you should give an explicit size to the container element, for example:
You can refer to common mistakes section for more information :)