Skip to content
Advertisement

MORE/LESS TOGGLE – Add Transition – Shopify/Javascript

I Have created a More/Less toggle button for which I have used https://jadepuma.com/blogs/blog/more-less-toggles-for-shopify-descriptions.

It works, but want to create a transition. When click read more button, it slowly opens the rest of the content. And click read less it slowly shuts.

This is what I am after, when button is toggled, it slowly reveals and closes the content: codepen.io/royketelaar/pen/avWxve

JavaScript
JavaScript

Advertisement

Answer

JavaScript
JavaScript

The Hide/Show Functions

$(element).hide/show(time(optional), easing(optional), callback(optional))

If you ignore all of the arguments except element, the function will do the same thing as what you did. These arguments can support these values:

Argument Supports(Depends on Browser)
element variable/element from HTML document
time number of milliseconds / ‘fast’ / ‘slow’
easing ‘linear’ / ‘swing’
callback function/action to do after hide/show function finishes

For example, this hide function

JavaScript

will make a transition to hide the help button for 1 second at a constant speed.

While this show function

JavaScript

will make a transition to show the navigation bar for 3/4 second at a slightly changing and easing speed. After the transition, it will write in the console “Transition Finished”.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement