44
` Thursday, February 28, 2013

Jquery at-webcamp

  • Upload
    gaplabs

  • View
    341

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Jquery at-webcamp

`

Thursday, February 28, 2013

Page 2: Jquery at-webcamp

Want to keep up with best practices?

Thursday, February 28, 2013

Page 3: Jquery at-webcamp

Want to make your site pop

with ?

Thursday, February 28, 2013

Page 4: Jquery at-webcamp

Want to make your site pop

with ?fancy effects

Thursday, February 28, 2013

Page 5: Jquery at-webcamp

Want to check if Javascript is enabled?

Thursday, February 28, 2013

Page 6: Jquery at-webcamp

Want to add neat hover states?

Thursday, February 28, 2013

Page 7: Jquery at-webcamp

Want to safely run your code when the page is loaded?

Thursday, February 28, 2013

Page 8: Jquery at-webcamp

Don’t want to use that pesky CSS?

Thursday, February 28, 2013

Page 9: Jquery at-webcamp

Don’t want to use boring vanilla Javascript?

Thursday, February 28, 2013

Page 10: Jquery at-webcamp

Just use !You know when you’re doing it right when you’re loading 12 jQuery plugins.

Thursday, February 28, 2013

Page 11: Jquery at-webcamp

JQuery

Thursday, February 28, 2013

Page 12: Jquery at-webcamp

• BASICS : Manipulating the DOM

• EVENTS

• EFFECTS

• AJAX : Processing in the Background

Thursday, February 28, 2013

Page 13: Jquery at-webcamp

JQuery javascript library designed to simplify client sidescripting

Thursday, February 28, 2013

Page 14: Jquery at-webcamp

How to Use JQuery

• include jQuery library

• write your SCRIPTS !!!

Thursday, February 28, 2013

Page 15: Jquery at-webcamp

Querying the DOMsearching the DOM for the elements or objects

$([selectors]) $(‘li’);

[selectors] can be

id - ex. #containerclass - ex. .listelement - ex. li

Thursday, February 28, 2013

Page 16: Jquery at-webcamp

.find()get the descendant of each element

syntax:

$(‘.list’).find(‘li’);

.children()get the children of each element

syntax:

$(‘.list’).children(‘li’);

Thursday, February 28, 2013

Page 17: Jquery at-webcamp

.parents()get the ancestors of each element

syntax:

$(‘.current’).parents(‘ul’);

.parent()get the parent of each element

syntax:

$(‘.current’).parent(‘ul’);

Thursday, February 28, 2013

Page 18: Jquery at-webcamp

.eq()select an element at index n

syntax:

$(‘.list’).find(‘li’).eq(2);

.next()get the following sibling element

.prev()get the preceding sibling element

syntax:

$(‘.list’).find(‘li’).eq(2).next();$(‘.list’).find(‘li’).eq(2).prev();

Thursday, February 28, 2013

Page 19: Jquery at-webcamp

Manipulating the DOM adding new elements, modifying, removing etc.

Thursday, February 28, 2013

Page 20: Jquery at-webcamp

.addClass()add specified classes

syntax:

$(‘.list’).children(‘li’).addClass(‘red’);

.removeClass()remove a single class

syntax:

$(‘.current’).removeClass(‘current’);

Thursday, February 28, 2013

Page 21: Jquery at-webcamp

.attr()return the value of an attribute

syntax:

$(‘.current’).find(‘a’).attr(‘href’);

Thursday, February 28, 2013

Page 22: Jquery at-webcamp

.before()append content before an element

.after()append content after an element

.append()append content at the end of an element

Thursday, February 28, 2013

Page 23: Jquery at-webcamp

$(‘.current’).append(‘<p>appended content</p>’);$(‘.list’).find(‘li’).eq(0).after(‘<li>content inserted by after</li>’);

Thursday, February 28, 2013

Page 24: Jquery at-webcamp

api.jquery.com

Thursday, February 28, 2013

Page 25: Jquery at-webcamp

JQueryEvents Handler

Thursday, February 28, 2013

Page 26: Jquery at-webcamp

What are Events?These methods are used to register behaviors to take effect when the user iteracts with the browser, and to further manipulate those registered behaviors.

Examples:• moving a mouse over an element• selecting a radio button• clicking on an element

Thursday, February 28, 2013

Page 27: Jquery at-webcamp

Javascript Events

Thursday, February 28, 2013

Page 28: Jquery at-webcamp

JQuery Advantage✓ All of the out-of-the-box functionality in jQuery are in reality extensions.

✓ This includes all the shorthands, like click(), hover(), toggle(), etc., but also the core-methods like bind(), each(), animate(), and so on.

✓ This means that you can detach functionality you are not using, making the library even smaller--file-size wise, as well as memory-footprint wise.

✓ This is pure design-genius!

Thursday, February 28, 2013

Page 29: Jquery at-webcamp

JQueryEvents Category

Thursday, February 28, 2013

Page 30: Jquery at-webcamp

Event Handler Attachment

Thursday, February 28, 2013

Page 31: Jquery at-webcamp

Browser Events

Thursday, February 28, 2013

Page 32: Jquery at-webcamp

Document Loading

Thursday, February 28, 2013

Page 33: Jquery at-webcamp

Form Events

Thursday, February 28, 2013

Page 34: Jquery at-webcamp

Keyboard Events

Mouse Events

Thursday, February 28, 2013

Page 35: Jquery at-webcamp

api.jquery.com

Thursday, February 28, 2013

Page 36: Jquery at-webcamp

JQuery has built in effects

Examples:$(h1).hide(“slow”);$(h1).fadeOut(2000);$(h1).slideDown(“fast”);

You can chain them

Examples:$(h1).fadeOut(1000). slideDown();

Animation

Thursday, February 28, 2013

Page 37: Jquery at-webcamp

JQuery animate()

Syntax:$(selector).animate({params}, speed, callback);

Example:$(“#block”).animate({ width: “100px”, opacity: 0.5, fontSize: “3em”, borderWidth: “10px”}, 1500);

Or roll your own

Thursday, February 28, 2013

Page 38: Jquery at-webcamp

api.jquery.com

Thursday, February 28, 2013

Page 39: Jquery at-webcamp

AJAX (Asynchronous Javascript and XML)

a technique used to send or retrieve data from a server in the background without interfering with the

current state of the page.

Thursday, February 28, 2013

Page 40: Jquery at-webcamp

JQuery AJAXSyntax:$.ajax(url, settings); OR SIMPLY$.ajax(settings);

where settings is a set of key/value pairs which JQuery calls PlainObject

e.g.{ key : value }

Thursday, February 28, 2013

Page 41: Jquery at-webcamp

Basic Settings

Thursday, February 28, 2013

Page 42: Jquery at-webcamp

urlthe url to which the request is sent

typethe type of request to make

e.g.POST, GET

datathe data to be sent to the server

e.g.{ “name” : “Juan”, “lastname” : “Dela Cruz” }or“name=Juan&lastname=Dela Cruz”

Thursday, February 28, 2013

Page 43: Jquery at-webcamp

dataTypethe type of data that you are expecting back from the server

e.g.xml, json, script, html, or text

errora function to be called if the request fails

successa function to be called if the request succeeds

completea function to be called when the request finishes (only executes after success and error callbacks are executed)

Thursday, February 28, 2013

Page 44: Jquery at-webcamp

api.jquery.com

Thursday, February 28, 2013