Comments (9)
@sanath1188
Thank you. I think there's an error with the initial value. I believe if you set it to 0, it will work as expected. I will fix this in the next days.
from keen-slider.
Hey @rcbyr, I'm still facing the OP's same issue. From reading the comments I think the issue is supposed to be fixed, but I still can't seem to get it working while using *ngFor
. I'm using Angular 10. If you could you please share a stackblitz or codesandbox of this, it'd be great! Thanks.
from keen-slider.
Hi @rcbyr , i'm having the same issue as @divinsmathew. When using ngFor in angular, the slides aren't showing, they are just blank. The data is fetched through an api, i'd like to know if there is a sample for this use case. Thanks so much for this useful project.
from keen-slider.
Hey @sanath1188
thank you. Currently, the slider does not observe any mutation on its own. So you need to tell the slider that there have been some changes. You could do this by calling the resize() function from the slider instance after the view has been updated.
Code-Example:
...
doResize: boolean = false
ngOnChanges(): void{
this.doResize = true
}
ngAfterViewChecked(): void{
if(this._slider && this.doResize) this._slider.resize()
this.doResize = false
}
...
from keen-slider.
Interesting. Still doesn't seem to work. Here's my code snippet:
HTML:
<div class="keen-slider" #sliderRef>
<div *ngFor="let number of numbers">
<!--Assume there's HTML enough to show numbers -->
</div>
</div>
TS:
ngAfterViewInit() {
this.slider = new KeenSlider(this.sliderRef.nativeElement, {
spacing: 40,
slidesPerView: 1,
initial: 4,
centered: true,
loop: false,
mode: "snap",
breakpoints: {
"(min-width: 768px)": {
slidesPerView: 2,
mode: "snap"
},
"(min-width: 1200px)": {
slidesPerView: 7,
mode: "snap"
}
}
});
}
ngAfterViewChecked(): void{
if(this.slider && this.dataLoaded) {
console.log("trying to resize")
this.slider.resize()
this.dataLoaded = false;
}
}
The variable dataLoaded
is set to true after an API loads the data. The function to call the API happens on ngOnInit()
from keen-slider.
@sanath1188 I just released a new version with a fix for that. Be aware of some style changes.
from keen-slider.
Still seeing the same problem with version 5.2.1, in this case on a React codebase.
const [sliderRef, slider] = useKeenSlider({
loop: true,
slideChanged(s) {
setCurrentSlide(s.details().relativeSlide);
},
});
useEffect(() => {
if (slider) {
slider.resize();
}
}, [images]);
When adding items to the slider (images array) the gallery seems to react correctly, but each time I remove items from the array even though the useEffect
runs and resize method too, the gallery does not remove the deleted item.
from keen-slider.
Hello @lmartins
I've created a small example with a button to remove slides and it works as expected. https://codesandbox.io/s/keen-slider-default-react-ts-zrzt1?file=/src/App.tsx
Can you create an example that will show your problem?
from keen-slider.
Hi @rcbyr, I was having the same issue and I found a alternative fix. The problem is after fetching data from an api and rendering the data using ngFor, there is a slight offset. So if you call update()
immediately after fetching the data, it might not be rendered and the class slider__slide
is not applied yet, which results in having the same slides
array as before.
To fix this you can use some sort of timeout and call update()
then.
/**
* Fetch some data from the API.
*/
public fetchSomeData(): void {
this.someDataService.getSomeData().subscribe({
next: (someData: SomeData[]) => {
this.someData = someData
if (this.keenSlider) {
setTimeout(() => {
this.keenSlider?.update(undefined, 0)
// Required when using indicator dots below the slides
this.updateDotHelper()
}, 1)
}
},
})
}
/**
* Updates the dot helper.
*/
private updateDotHelper(): void {
if (this.keenSlider) {
this.dotHelper = [
...Array(this.keenSlider.track.details.slides.length).keys(),
]
}
}
from keen-slider.
Related Issues (20)
- Vertical auto-switch unexpected behavior after several seconds HOT 1
- Drag deceleration speed
- Stop moveToIdx move backward on loop
- I wonder why there's such a blank area
- [React] Stop auto switch after navigation
- Lazy loading when slides.perView > 1
- scrolling issue on mobile with scroll variant of "data-keen-slider-scrollable".
- SyntaxError: Named export 'useKeenSlider' not found.
- [Angular] ReferenceError: document is not defined
- Keen-slider doesn't work properly with vue-transition.
- Slider Switches Slide After Very Short Drag
- Click while sliding with free-snap mode HOT 1
- [VanillaJS][v5] translate3d values for slides are sometimes wrong
- How to avoid skipping slides when mouse scrolling? HOT 1
- moveToIdx does not work in certain conditions HOT 3
- Dynamic content makes slides jumping between loops
- Scrolling to a Specific Element in a Multi-Element Slide
- Weird Resize Happening to All Slides HOT 1
- Control end animation speed
- Autosroll issue
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from keen-slider.