Mootools 1.2 tutorial sliding effect (Slide)_Mootools
Basic Usage
Like all the classes we have seen before, when we apply this class to an element, the first thing we have to do is to initialize a new Fx.Slide instance.
First, let’s create an HTML file for the sliding element.
Reference code:
Our CSS doesn’t need any modification either.
Reference code:
.slide {
margin: 20px 0;
padding: 10px;
width: 200px;
background-color: #DAF7B4;
}
Finally, let’s initialize a new Fx.Slide and pass it our element variable.
Reference code:
var slideElement = $(' slide_element');
var slideVar = new Fx.Slide(slideElement, {
// Fx.Slide options
mode: 'vertical', // The default is 'vertical' (vertical)
/ / Fx option
transition: 'sine:in',
duration: 300,
// Fx event
onStart: function(){
$('start').highlight(" #EBCC22");
}
});
Since Fx.Slide is an extension of Fx, you can use any options and events of Fx, but Fx.Slide also has Some options of your own.
Fx.Slide options
Fx.Slide has only two options - "mode" and "wrapper". Frankly, I've never found myself using "wrapper" (I've never encountered the need), but "mode" determines whether you want to slide horizontally or vertically.
mode (mode)
Mode gives you two choices - "vertical" or "horizontal". Vertical is displayed from top to bottom, horizontal is displayed from left to right. There is no bottom to top or right to left option here. But I know it's relatively simple to modify the class itself to implement these functions. In my opinion I would still like this to become a standard option, if anyone has modified this class to allow these options please drop us a line.
wrapper
By default, Fx.Slide will add a wrapper outside your sliding element and assign the value of its "overflow" attribute to "hidden". wrapper allows you to set other elements as wrappers for this element. Like I said above, I don't know where it would be used, and I'd be interested in hearing any thoughts on this. (Thanks to horseweapon from mooforum.net for making me understand this.)
Methods of Fx.Slide
Fx.Slide also provides many methods to show or hide elements.
.slideIn()
As the name tells you, this method triggers the start time and displays your element.
.slideOut()
Slide the element to the hidden state.
.toggle()
This method may show or hide the element, and the result depends entirely on the current state of the element. Very useful for click events.
.hide()
This will hide the element but not use the sliding effect.
.show()
This will show the element but not use the sliding effect.
Reset mode options through methods
Each of the above methods can accept an optional mode parameter, allowing you to override previously set options.
Reference code:
slideVar.slideIn('horizontal ');
Fx.Slide shortcut
The Fx.Slide class also provides some very convenient shortcuts to add sliding effects to elements.
.set('slide');
You can create a new slide instance by adding a slide object to the element through the set method without initializing a new class.
Reference code:
slideElement.set('slide ');
Set options
You can even set options through shortcuts:
Reference code:
slideElement.set('slide', {duration: 1250});
.slide()
Once a slide is set using the .set() method, you can initialize it using the .slide() method.
Reference code:
slideElement.slide('in');
.slide method can accept the following parameters:
'in'
'out'
'toggle'
'show'
'hide'
Each parameter corresponds to the method above.
Code examples
The above basically covers all basic usage. The example below will use most of what we learned above to show a few different sliding elements and provide some divs as indicators so you can clearly see these events.
First, create the HTML file.
Reference code:
< button id="openB">open B
Next is the CSS file. We keep it as simple as possible.
Reference code:
.ind {
width: 200px;
padding: 10px;
background-color: #87AEE1;
font-weight: bold;
border-bottom: 1px solid white;
}
.slide {
margin: 20px 0;
padding: 10px;
width: 200px;
background-color: #DAF7B4;
}
#slide_wrap {
padding: 30px;
background-color: #D47000;
}
Finally, our Mootools JavaScript code:
Reference code:
window.addEvent('domready', function() {
// Example A
var slideElement = $('slideA');
var slideVar = new Fx.Slide(slideElement , {
// Fx.Slide option
mode: 'horizontal', // The default is 'vertical'
//wrapper: this.element, // The default is this.element
// Fx options
link: 'cancel',
transition: 'elastic:out',
duration: 'long',
// Fx event
onStart: function(){
$('start').highlight("#EBCC22");
},
onCancel: function(){
$('cancel').highlight("#EBCC22");
},
onComplete: function(){
$('complete').highlight("#EBCC22");
}
}).hide().show().hide() ; // Note that the .hide and .show methods do not trigger events
$('openA').addEvent('click', function(){
slideVar.slideIn();
});
$('closeA').addEvent('click', function(){
slideVar.slideOut();
});
// Example B
var slideElementB = $( 'slideB');
var slideVarB = new Fx.Slide(slideElementB, {
// Fx.Slide options
mode: 'vertical', // The default is 'vertical'
// Fx Options
// Note: The chain effect allows you to click multiple times,
// When the mouse leaves,
// the animation of each click can be triggered in sequence
link: 'chain',
// Fx event
onStart: function(){
$('start').highlight("#EBCC22");
},
onCancel: function(){
$('cancel').highlight("#EBCC22");
},
onComplete: function(){
$('complete').highlight("#EBCC22");
}
});
$('openB').addEvent('click', function(){
slideVarB.slideIn();
});
$('closeB ').addEvent('click', function(){
slideVarB.slideOut();
});
// Example C
var slideElementC = $('slideC');
var slideVarC = new Fx.Slide(slideElementC, {
// Fx.Slide options
mode: 'vertical', // The default is 'vertical'
//wrapper: this.element, // The default is this.element
// Fx options
//link: 'cancel',
transition: 'sine:in',
duration: 300,
// Fx event
onStart: function(){
$('start').highlight("#EBCC22");
},
onCancel: function(){
$('cancel').highlight ("#EBCC22");
},
onComplete: function(){
$('complete').highlight("#EBCC22");
}
}).hide ();
$('openC').addEvent('click', function(){
slideVarC.toggle();
});
$('slideD').slide( 'hide');
$('openD').addEvent('click', function(){
$('slideD').slide('toggle');
});
//Example C
var slideElementE = $('slideE');
var slideWrap = $('slide_wrap');
var slideVarE = new Fx.Slide(slideElementE, {
// Fx.Slide options
//mode: 'vertical', // The default is 'vertical'
wrapper: slideWrap // The default is this.element
}).hide();
$( 'openE').addEvent('click', function(){
slideVarE.toggle();
});
});
Learn more…
Fx.Slide is a multifunctional and very useful plug-in. To learn more, check out the Fx.Slide Documentation, Fx.Morph and the Fx Documentation .
Also, be sure to read our tutorial about Fx.Morph and Fx Options and Events.
Download the zip file of the final example code
Contains everything you need to get started.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Detailed explanation of JavaScript string replacement method and FAQ This article will explore two ways to replace string characters in JavaScript: internal JavaScript code and internal HTML for web pages. Replace string inside JavaScript code The most direct way is to use the replace() method: str = str.replace("find","replace"); This method replaces only the first match. To replace all matches, use a regular expression and add the global flag g: str = str.replace(/fi

This tutorial shows you how to integrate a custom Google Search API into your blog or website, offering a more refined search experience than standard WordPress theme search functions. It's surprisingly easy! You'll be able to restrict searches to y

So here you are, ready to learn all about this thing called AJAX. But, what exactly is it? The term AJAX refers to a loose grouping of technologies that are used to create dynamic, interactive web content. The term AJAX, originally coined by Jesse J

This article series was rewritten in mid 2017 with up-to-date information and fresh examples. In this JSON example, we will look at how we can store simple values in a file using JSON format. Using the key-value pair notation, we can store any kind

Leverage jQuery for Effortless Web Page Layouts: 8 Essential Plugins jQuery simplifies web page layout significantly. This article highlights eight powerful jQuery plugins that streamline the process, particularly useful for manual website creation

Core points This in JavaScript usually refers to an object that "owns" the method, but it depends on how the function is called. When there is no current object, this refers to the global object. In a web browser, it is represented by window. When calling a function, this maintains the global object; but when calling an object constructor or any of its methods, this refers to an instance of the object. You can change the context of this using methods such as call(), apply(), and bind(). These methods call the function using the given this value and parameters. JavaScript is an excellent programming language. A few years ago, this sentence was

jQuery is a great JavaScript framework. However, as with any library, sometimes it’s necessary to get under the hood to discover what’s going on. Perhaps it’s because you’re tracing a bug or are just curious about how jQuery achieves a particular UI

This post compiles helpful cheat sheets, reference guides, quick recipes, and code snippets for Android, Blackberry, and iPhone app development. No developer should be without them! Touch Gesture Reference Guide (PDF) A valuable resource for desig
