I want to truncate the text of the Bootstrap carousel .carousel-caption
element. I am using shave.js to truncate the text. However, the truncating only works on the first .carousel-caption
element.
I`ve created a jsfiddle to demonstrate my problem: jsfiddle
When I remove the CSS class carousel-inner
from the carousel, the truncating works perfectly on booth .carousel-caption
elements.
2
Answers
I am not pretty sure about the issue, but I think it’s due to the dynamic behavior of the carousel so the shave code will only work on the first caption because it’s visible and its height is set so your code should also be dynamic to call the shave funcion for each slide.
An idea is to use the event provided by the carousel component and call the shave function there.
Full code : https://jsfiddle.net/dpnpo4o7/2/
I used the jQuery version of the plugin in the code above but it works the same with the JS version:
Full code : https://jsfiddle.net/dpnpo4o7/3/
I went through the fiddle. And shave must be finding those second captions but since it is invisible at that moment, it is failing to do that.
Solution: You might want to capture the prev and next events and then try your code.