Documentation Index Fetch the complete documentation index at: https://mintlify.com/ganlanyuan/tiny-slider/llms.txt
Use this file to discover all available pages before exploring further.
Overview
The TinySliderInfo object contains comprehensive information about the current state of the slider. You can access it via:
The getInfo() method
Event callback parameters
const slider = tns ({ container: '.my-slider' });
// Method 1: Using getInfo()
const info = slider . getInfo ();
console . log ( 'Current index:' , info . index );
// Method 2: Event callbacks
slider . events . on ( 'indexChanged' , function ( info ) {
console . log ( 'Current index:' , info . index );
});
Interface Definition
interface TinySliderInfo {
event : Event | {};
container : HTMLElement ;
slideItems : HTMLCollection ;
navContainer ?: HTMLElement ;
navItems ?: HTMLCollection ;
controlsContainer ?: HTMLElement ;
hasControls : boolean ;
prevButton ?: HTMLElement ;
nextButton ?: HTMLElement ;
items : number ;
slideBy : number ;
cloneCount : number ;
slideCount : number ;
slideCountNew : number ;
index : number ;
indexCached : number ;
displayIndex : number ;
navCurrentIndex ?: number ;
navCurrentIndexCached ?: number ;
pages ?: number ;
pagesCached ?: number ;
sheet : CSSStyleSheet ;
isOn : boolean ;
}
Properties
event
The browser event object that triggered this info update, or an empty object if not triggered by an event. slider . events . on ( 'indexChanged' , function ( info ) {
console . log ( 'Event type:' , info . event . type );
});
container
The main slider container element. const info = slider . getInfo ();
console . log ( 'Container ID:' , info . container . id );
console . log ( 'Container width:' , info . container . offsetWidth );
slideItems
A live HTMLCollection of all slide elements (including clones in carousel mode). const info = slider . getInfo ();
console . log ( 'Total slides:' , info . slideItems . length );
// Access current slide
const currentSlide = info . slideItems [ info . index ];
console . log ( 'Current slide HTML:' , currentSlide . innerHTML );
index
The current slide index (zero-based). This is the index of the first visible slide. const info = slider . getInfo ();
console . log ( 'Current slide index:' , info . index );
console . log ( 'Current slide (1-based):' , info . index + 1 );
// Check if at first slide
if ( info . index === 0 ) {
console . log ( 'At first slide' );
}
// Check if at last slide
if ( info . index === info . slideCount - 1 ) {
console . log ( 'At last slide' );
}
indexCached
The previous slide index (before the current transition). Useful for comparing before/after states. slider . events . on ( 'indexChanged' , function ( info ) {
console . log ( 'Moved from slide' , info . indexCached , 'to slide' , info . index );
const direction = info . index > info . indexCached ? 'forward' : 'backward' ;
console . log ( 'Direction:' , direction );
});
slideCount
The original number of slides (before cloning for carousel mode). const info = slider . getInfo ();
console . log ( 'Total slides:' , info . slideCount );
console . log ( 'Progress:' , ` ${ info . index + 1 } / ${ info . slideCount } ` );
slideCountNew
The total number of slides after initialization, including clones created for carousel mode. const info = slider . getInfo ();
console . log ( 'Original slides:' , info . slideCount );
console . log ( 'Total slides (with clones):' , info . slideCountNew );
console . log ( 'Cloned slides:' , info . cloneCount );
cloneCount
The number of cloned slides created for seamless looping in carousel mode. const info = slider . getInfo ();
if ( info . cloneCount > 0 ) {
console . log ( 'Carousel mode with' , info . cloneCount , 'clones' );
}
items
The number of slides currently visible in the viewport. const info = slider . getInfo ();
console . log ( 'Visible slides:' , info . items );
// Calculate how many pages
const totalPages = Math . ceil ( info . slideCount / info . items );
console . log ( 'Total pages:' , totalPages );
slideBy
The number of slides that move on each navigation action. const info = slider . getInfo ();
console . log ( 'Slides per action:' , info . slideBy );
if ( info . slideBy === info . items ) {
console . log ( 'Moving one full page at a time' );
}
hasControls
Indicates whether the slider has prev/next control buttons. const info = slider . getInfo ();
if ( info . hasControls ) {
console . log ( 'Controls are enabled' );
}
controlsContainer
The HTMLElement that contains the prev/next control buttons, if using a custom controls container. const info = slider . getInfo ();
if ( info . controlsContainer ) {
console . log ( 'Using custom controls container:' , info . controlsContainer );
}
The previous button element, if controls are enabled. const info = slider . getInfo ();
if ( info . prevButton ) {
console . log ( 'Prev button:' , info . prevButton );
// Check if disabled
if ( info . prevButton . disabled ) {
console . log ( 'Prev button is disabled' );
}
}
The next button element, if controls are enabled. const info = slider . getInfo ();
if ( info . nextButton ) {
console . log ( 'Next button:' , info . nextButton );
// Add custom event
info . nextButton . addEventListener ( 'click' , () => {
console . log ( 'Next button clicked' );
});
}
navContainer
The navigation dots container element, if nav is enabled. const info = slider . getInfo ();
if ( info . navContainer ) {
console . log ( 'Nav container:' , info . navContainer );
}
navItems
navItems
HTMLCollection | undefined
A live HTMLCollection of navigation dot elements. const info = slider . getInfo ();
if ( info . navItems ) {
console . log ( 'Number of nav dots:' , info . navItems . length );
// Find active dot
Array . from ( info . navItems ). forEach (( dot , index ) => {
if ( dot . classList . contains ( 'tns-nav-active' )) {
console . log ( 'Active dot index:' , index );
}
});
}
navCurrentIndex
The current active navigation dot index. slider . events . on ( 'indexChanged' , function ( info ) {
if ( info . navCurrentIndex !== undefined ) {
console . log ( 'Active nav dot:' , info . navCurrentIndex );
}
});
navCurrentIndexCached
The previous active navigation dot index. slider . events . on ( 'indexChanged' , function ( info ) {
console . log ( 'Nav changed from' , info . navCurrentIndexCached , 'to' , info . navCurrentIndex );
});
displayIndex
The current slide index for display purposes (1-based instead of 0-based). const info = slider . getInfo ();
console . log ( 'Slide ' + info . displayIndex + ' of ' + info . slideCount );
pages
The number of visible navigation pages/dots. const info = slider . getInfo ();
if ( info . pages !== undefined ) {
console . log ( 'Visible nav pages:' , info . pages );
}
pagesCached
The previous number of visible navigation pages/dots. const info = slider . getInfo ();
console . log ( 'Previous visible nav pages:' , info . pagesCached );
sheet
The CSSStyleSheet object used by the slider for dynamic styles. const info = slider . getInfo ();
console . log ( 'Stylesheet:' , info . sheet );
isOn
Indicates whether the slider is currently active/initialized. const info = slider . getInfo ();
if ( info . isOn ) {
console . log ( 'Slider is active' );
}
Usage Examples
Basic Info Access
Custom Counter
Progress Bar
Detect Direction
Access Current Slide
Disable Nav at Boundaries
Custom Thumbnails
Conditional Content Loading
Keyboard Navigation Feedback
Responsive Info
const slider = tns ({
container: '.my-slider' ,
items: 3
});
const info = slider . getInfo ();
console . log ( 'Current slide:' , info . index + 1 );
console . log ( 'Total slides:' , info . slideCount );
console . log ( 'Visible items:' , info . items );
console . log ( 'Slide by:' , info . slideBy );
Common Patterns
Display Current Position
function displayPosition () {
const info = slider . getInfo ();
return ` ${ info . index + 1 } / ${ info . slideCount } ` ;
}
Calculate Pages
function getTotalPages () {
const info = slider . getInfo ();
return Math . ceil ( info . slideCount / info . items );
}
function getCurrentPage () {
const info = slider . getInfo ();
return Math . floor ( info . index / info . items ) + 1 ;
}
Check Boundaries
function isAtStart () {
const info = slider . getInfo ();
return info . index === 0 ;
}
function isAtEnd () {
const info = slider . getInfo ();
return info . index >= info . slideCount - info . items ;
}
Get Visible Slides
function getVisibleSlides () {
const info = slider . getInfo ();
const visible = [];
for ( let i = 0 ; i < info . items ; i ++ ) {
const slideIndex = info . index + i ;
if ( slideIndex < info . slideCount ) {
visible . push ( info . slideItems [ slideIndex ]);
}
}
return visible ;
}
Tips
The info object is always current and reflects the latest slider state. You don’t need to cache it - just call getInfo() whenever you need fresh data.
slideItems is a live HTMLCollection. If you modify the DOM, the collection updates automatically. Convert to an array if you need a static snapshot: Array.from(info.slideItems).
When working with events, always use the info parameter passed to your callback instead of calling getInfo() separately - it’s more efficient and guaranteed to match the event state.