Mootools 1.2 Slide)

Source: Internet
Author: User
Tags mootools
Document directory
  • Learn more ......

Basic usage
Just like all the classes we have seen before, when we apply this class to an element, the first thing we need to do is to initialize a new Fx. Slide instance.
First, let's create an HTML file for the sliding element.
Reference code: Copy codeThe Code is as follows: <div id = "slide_element" class = "slide"> here is the content to slide. </Div>

Our CSS does not require any modification.
Reference code:Copy codeThe Code is as follows:. slide {
Margin: 20px 0;
Padding: 10px;
Width: 200px;
Background-color: # DAF7B4;
}

Finally, we initialize a new Fx. Slide and pass it our element variable.
Reference code:Copy codeThe Code is as follows: var slideElement = $ ('slide _ element ');
Var slideVar = new Fx. Slide (slideElement ,{
// Fx. Slide Option
Mode: 'signature', // The default value is 'version' (vertical)
// Fx Options
Transition: 'sine: in ',
Duration: 300,
// Fx event
OnStart: function (){
$ ('Start'). highlight ("# EBCC22 ");
}
});

As Fx. Slide is an extension of Fx, you can use any options and events of Fx, but Fx. Slide also has some options.
Fx. Slide Option
Fx. Slide has only two options: "mode" and "wrapper ". Frankly speaking, I have never found myself using "wrapper" (I have never encountered such a requirement), but "mode" determines whether you want horizontal or vertical sliding.
Mode)
The Mode gives you two options-vertical or horizontal ". Vertical is the display from the top to the bottom, and horizontal is the display from the left to the right. There is no option from bottom to top or from right to left. However, I know that modifying the class itself to implement these functions is relatively simple. In my opinion, I still hope this will become a standard option. If someone has modified this class and allowed these options, please leave us a message.
Wrapper)
By default, Fx. Slide adds a wrapper to the outside of your sliding element and specifies the value of its "overflow" attribute as "hidden ". Wrapper allows you to set other elements as the package for this element. As I said above, I don't know where it will be used, and I am also interested in hearing any thoughts about it. (Thanks to the horseweapon of mooforum.net for letting me understand this .)
Fx. Slide Method
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 elements.
. SlideOut ()
Slide the element to the hidden state.
. Toggle ()
This method may display or hide an element. The result depends entirely on the current state of the element. It is useful when you click an event.
. Hide ()
This hides the element, but does not use the slide effect.
. Show ()
This will show the elements, but will not use the slide effect.
Reset mode options by using methods
Each method above can accept an optional mode parameter, allowing you to overwrite the previously set options.
Reference code:Copy codeThe Code is as follows: slideVar. slideIn ('horizontal ');

Fx. Slide shortcut
The Fx. Slide class also provides convenient shortcuts for adding sliding effects to elements.
. Set ('slide ');
Instead of initializing a new class, you can use the set method to add a slide object to the element to create a new slide instance.
Reference code:Copy codeThe Code is as follows: slideElement. set ('slide ');

Set options
You can even set options through shortcuts:
Reference code:Copy codeThe Code is as follows: slideElement. set ('slide', {duration: 1250 });

. Slide ()
Once slide is set using the. set () method, you can use the. slide () method to initialize it.
Reference code:Copy codeThe Code is as follows: slideElement. slide ('in ');

The. slide method can take the following parameters:
'In'
'Out'
'Toggle'
'Show'
'Hide'
Each parameter corresponds to the preceding method.
Sample Code
The above mentioned basic covers all basic usage. The following example uses most of the knowledge we have learned to show some different sliding elements and provides some divs as indicators so that you can clearly see these events.
First, create an HTML file.
Reference code:Copy codeThe Code is as follows: <div id = "start" class = "ind"> Start </div>
<Div id = "cancel" class = "ind"> Cancel </div>
<Div id = "complete" class = "ind"> Complete </div>
<Br/>
<Button id = "openA"> open A </button>
<Button id = "closeA"> close A </button>
<Div id = "slideA" class = "slide"> Here is some content-. notice the delay before onComplete fires. this is due to the transition effect, the onComplete will not fire until the slide element stops "elasticing. "Also, notice that if you click back and forth, it will" cancel "the previous call and give the new one priority. </div>
<Button id = "openB"> open B </button>
<Button id = "closeB"> close B </button>
<Div id = "slideB" class = "slide"> Here is some content-B. notice how if you click me multiple times quickly I "chain" the events. this slide is set up with the option "link: 'chain'" </div>
<Button id = "openC"> toggle C </button>
<Div id = "slideC" class = "slide"> Here is some content-C </div>
<Button id = "openD"> toggle D </button>
<Div id = "slideD" class = "slide"> Here is some content-D. notice how I am not hooked into any events. this was done with. slide shortcut. </div>
<Button id = "openE"> toggle E </button>
<Div id = "slide_wrap">
<Div id = "slideE" class = "slide"> Here is some content-E </div>
</Div>

Next is the CSS file. Let's keep it as simple as possible.
Reference code:Copy codeThe Code is as follows:. 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:Copy codeThe Code is as follows: window. addEvent ('domainready', function (){
// Example
Var slideElement = $ ('slidea ');
Var slideVar = new Fx. Slide (slideElement ,{
// Fx. Slide Option
Mode: 'horizontal ', // The default value is 'version'
// Wrapper: this. element, // The default value 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. 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 Option
Mode: 'version', // The default value is 'version'
// Fx Options
// Note: The chain effect allows you to click multiple times,
// When the mouse leaves,
// The animation that you 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 Option
Mode: 'version', // The default value is 'version'
// Wrapper: this. element, // The default value 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 Option
// Mode: 'signature', // The default value is 'version'
Wrapper: slideWrap // The default value is this. element.
}). Hide ();
$ ('Opene'). addEvent ('click', function (){
SlideVarE. toggle ();
});
});

Learn more ......

Fx. Slide is a versatile and useful plug-in. To learn more, see Fx. Slide documentation, Fx. Morph and Fx documentation.

Also, read our tutorials on Fx. Morph and Fx Options and events.

Download the zip compressed file of the final sample code

Contains everything you need.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.