Manipulation

scrollTop( [value][, duration] )

Set the current vertical position of the scroll bar for each of the set of matched elements.

Value (optional):
Type: int
Default: 0
A number indicating the new position to set the scroll bar to.
Duration (optional):
Type: int
Default: 250
A number determining how long the animation will run.

Limitations in AMP:

  • scrollTop can be applied only to body

Example

$(.scroll-to-top’).on(‘click’, (e) => {
$(body).scrollTop();
});

show()

Display the matched elements.

Example

$(‘button’).on(‘click’, (e) => {
$(.message’).show();
});

hide()

Hide the matched elements.

Example

$(‘button’).on(‘click’, (e) => {
$(.message’).hide();
});

addClass(className[, className....])

Adds the specified class(es) to each element in the set of matched elements.

ClassName
Type: string
The css class to be added to the class attribute.

Example

$(‘button’).on(‘click’, (e) => {
$(.menu’).addClass(‘active’, ‘large’);
});

removeClass(className[, className....])

Removes the specified class(es) to each element in the set of matched elements.

ClassName
Type: string
The css class to be added to the class attribute.

Example

$(‘button’).on(‘click’, (e) => {
$(.menu’).removeClass(‘active’, ‘large’);
});

toggleClass(className[, className....])

Add or remove one or more classes from each element in the set of matched elements, depending on either the class' presence or the value of the state argument.

ClassName
Type: string
The css class to be added to the class attribute.

Example

$(‘button’).on(‘click’, (e) => {
$(.menu’).toggleClass(‘open’);
});

toggle()

Display or hide the matched elements.

Example

$(‘button’).on(‘click’, (e) => {
$(.menu’).toggle();
});