vitalii-andriiovskyi / ngx-owl-carousel-o

owl-carousel for Angular >=6
MIT License
177 stars 51 forks source link

Carousel problem reinitialize or refresh box width #204

Open corsaronero opened 2 years ago

corsaronero commented 2 years ago

Hi i add two image for better explain the problem the first image show the when the page init with the lateral panel open

Capture33

the second image show when i close the panel and the carousel is not resized so you can see in the last image the space to the arrow

Capture34

does anyone know how to fix this? Thanks.

vitalii-andriiovskyi commented 2 years ago

Hi @corsaronero

The code doesn't watch the changes of host DOM width and doesn't rerender the carousel after any such change. In your case this width changes if to open/close the sidebar. Browser resizing, changes of options, and changes of slides data can make the carousel rerender.

So you can change options via destructuring like here or fire the event resize

emregan commented 2 years ago

Hi @vitalii-andriiovskyi , thank you for all the awesome work on this. Question: in Angular, how can how can I fire the event resize so that it triggers the carousel to rerender when I actually resize the window? I have a listener for window onresize, however I don't think the carousel is recognizing it. Please help - thank you!

vitalii-andriiovskyi commented 2 years ago

Hi @emregan

The carousel listens to window resizing. So if you resize window, it rerenders. Take into account, if you use responsive option, width you supply to it, is the width of the container holding the carousel, not the width of the window.

window.dispatchEvent(new Event('resize')); works in Angular too. But be carefull using window directly. If you have server-side rendering such usage will lead to the error.

ch-ivy commented 2 years ago

Hi @vitalii-andriiovskyi please can you show a code sample of firing this resize event