Documentation On Jquery
Documentation On Jquery
where "thing to touch" is the HTML element you'll click on, hover over, or otherwise
interact with, and "thing to affect" is the HTML element that fades away, changes size,
or undergoes some other transformation. Sometimes these elements are one and the
sameyou might hover over a<div> to change its opacity. Other times, you might
interact with a separate element; for example, you might click on a button to resize a
<div>.Sometimes if you want an effect to occur right away, without an event
like.click() or .hover(), you'll skip the second line in the above:
$(document).ready(function() {
$('thingToAffect').effect();
});
Before :
After :
After :
Before :
After:
6. Hover
What if you wanted to create an effect when your mouse is on top of an object, then
have that effect vanish when your mouse moved away? You might notice this effect in
use on many site's navigation bars!
$('div').hover(
function(){
$(this).addClass('highlight');
},
function(){
$(this).removeClass('highlight');
}
);
After :
7. Let's .focus()!
Another event we can make use of is.focus(). We say an element has focus when we
click on it or tab over to it. If you've ever filled out a form on a web page and seen how
each text box lights up when you tab to it or click on it, you've seen focus in action!
The .focus() event handler only works on elements that can receive focusthe list of
these elements is a bit vague, but HTML elements like<textarea>s and <input>s are the
usual suspects.
Check out the form we've set up in the Result tab. If you click on the input field, you'll
see it automatically highlights in a delightful baby blue. Too bad baby blue is for babies!
We want our highlighting to be red.
We can do this with two tools:.focus() and our .css() function from the last section. We
want to write a bit of jQuery code that will change our 'input''s 'outlinecolor' to'red' when it gains focus.
Before :
After :
This will take the first div it finds and move it ten pixels to the right. Remember, increasing
the distance from the left margin moves something to the right; the += bit is just a shorthand
for "take the existing number and add ten to it." In this case, it add ten pixels to the current
distance from the left margin.
Before :
After :
1. The left arrow key on our keyboards translates to number 37 to the computer.
When that key is pressed, we animate our image to the left by subtracting 10px
2. To move up we subtract 10px from the top
3. To move right we add 10px to the left
4. Finally, to move down we add 10pxto the top
Before :
After :
1. Hiding an Object
Before :
After :
The object will
hide once the
.hide() code
used.
Where the bit between curly braces says "hey, jQuery! Add 10 pixels to the current top
margin," and the second input says "do it in 500 milliseconds!" (1,000 milliseconds =
one second.)
Before :
After :
3. Introducing: jQuery UI
jQuery UI includes a number of ultra-fancy animations you can use to make your
websites do incredible things.For instance, remember when we lamented that jQuery
didn't include a.blowUp() effect for our planet Krypton? Well, that's still true. But jQuery
UI has an .effect() effect, and we are totally going to give it the input'explode'.Note that
we've included an extra<script> tag in our HTML documents; this is used to include
jQuery UI in our webpages.