Changing Options
The initReadMore
function allows configuring the behavior of the «Read More» plugin through a parameters object. This enables adapting content display, animation, and interaction to your site's needs.
With flexible settings, you can create a user-friendly and aesthetically appealing interface that aligns with your project's design and functional requirements.
Below is a detailed description of all available parameters:
Defines the initial height of collapsed content in pixels. If the content is shorter than this height, the «Read More» button is not displayed.
Sets the duration of the expand/collapse animation in milliseconds. For collapsing in animationMode: 'js'
mode, the speed is halved.
HTML string for the «Read More» button displayed in the collapsed state. Inserted into a <button>
element. For security, HTML is sanitized of potentially dangerous attributes.
HTML string for the «Close» button displayed in the expanded state. Inserted into a <button>
element. Supports sanitization of HTML from unsafe code.
If true
, the button is hidden after expanding the content, avoiding unnecessary interface elements.
If true
, disables the collapse function for an element or screen width range, displaying the full content.
Defines the type of animation:
js
: Animation via JavaScript with smooth height transition.css
: Animation via CSS, adds thecs_readmore-animation
class for styling.
Sets the transition type for animation in animationMode: 'js'
mode. Available values: linear
, ease
, ease-in
, ease-out
, ease-in-out
.
If true
, the page smoothly scrolls to the top of the content after collapsing, improving viewing convenience.
Allows setting different parameter values based on screen width. Keys are the maximum screen width in pixels, values are an object with parameters.
Example:
breakpoints: {
768: {
collapsedHeight: 150,
moreLink: '<span>Read More</span>'
},
1200: { collapsedHeight: 200 }
}
If the screen width exceeds the maximum key, collapsing is disabled.
Callback invoked before expanding/collapsing starts. Receives arguments: button
(button), element
(content element), isExpanded
(boolean state).
Example:
beforeToggle: (button, element, isExpanded) => {
console.log('Toggle will start, state:', isExpanded);
}
Callback invoked after expanding/collapsing completes. Receives the same arguments: button
, element
, isExpanded
.
Example:
afterToggle: (button, element, isExpanded) => {
console.log('Toggle completed, state:', isExpanded);
}
Callback invoked after the plugin processes an element. Receives arguments: element
(content element), needsToggle
(boolean indicating if a button is needed).
Example:
blockProcessed: (element, needsToggle) => {
console.log('Element processed, button needed:', needsToggle);
}