1. Trang chủ
  2. » Công Nghệ Thông Tin

jQuery Essentialsby Marc Grabanskiv2.We needed a hero to get these guys in line.jQuery ppt

115 194 0
Tài liệu đã được kiểm tra trùng lặp

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Tiêu đề jQuery Essentials by Marc Grabanski v2
Tác giả Marc Grabanski
Thể loại Presentation
Định dạng
Số trang 115
Dung lượng 5,05 MB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

Selector Examples$“li:first” get first list item... Selector Examples$“li:first” get first list item... jQuery Factory Method $You can also pass $ a functionto run the function after the

Trang 1

jQuery Essentials

by Marc Grabanski

v2

Trang 2

We needed a hero to get these guys in line

Trang 3

jQuery rescues us by working the same in all browsers!

Trang 4

Easier to write jQuery than pure JavaScript

Trang 7

HTML is tied to JavaScript

Trang 8

jQuery Philosophy

Trang 9

#1 Find some HTML jQuery Philosophy

Trang 10

#1 Find some HTML

#2 Do something to it jQuery Philosophy

Trang 11

Find

Trang 12

elements

Trang 13

Give $() a selector

Trang 14

Give $() a selector

$(“ #myId ”)

Trang 15

Give $() a selector

$(“ #myId ”) $(“ myClass ”)

Trang 16

Give $() a selector

$(“ #myId ”) $(“ myClass ”) $(“ table ”)

Trang 17

Selector Examples

Trang 18

Selector Examples

$(“li:first”) get first list item

Trang 19

Selector Examples

$(“li:first”) get first list item

Trang 20

Selector Examples

$(“li:first”) get first list item

get all links who’s target is “_blank”

Trang 21

Selector Examples

$(“li:first”) get first list item

Trang 22

You can also string selectors together

Trang 23

You can also string selectors together

$(“ #myId, myClass, table ”)

Trang 24

Find

Trang 25

Do addClass(“ redbox ”);

$(“div”)

Find

Trang 26

jQuery API Spice

Two things that make the API HOT

Trang 27

Chain Methods

Trang 28

Chain Methods

.fadeOut();

Trang 29

$( ) html();

One Method, Many Uses

Trang 30

$( ) html();

One Method, Many Uses

Trang 32

jQuery Methods

Trang 33

• Moving Elements:

append (), appendTo (), before (), after (),

Trang 39

jQuery Factory Method $()You can also pass $() a function

to run the function after the page loads

Trang 40

jQuery Factory Method $()

You can also pass $() a function

to run the function after the page loads

});

Trang 41

jQuery Factory Method $()

You can also pass $() a function

to run the function after the page loads

});

code here will execute after DOM is ready

Trang 42

jQuery Factory Method $()

You can also pass $() a function

to run the function after the page loads

});

Note: This is essentially the same as

code here will execute after DOM is ready

Trang 43

jQuery Factory Method $()

You can also pass $() a function

to run the function after the page loads

});

Note: This is essentially the same as

code here will execute after DOM is ready

you will see this in tutorials around the net

Trang 47

Move paragraphs to element with id “foo”

Moving Elements Examples

Trang 48

Move paragraphs to element with id “foo”

Moving Elements Examples

.appendTo(“#foo”);

Trang 50

Attributes

Trang 51

Get

Trang 52

.attr(‘id’)

Get

.html()

Trang 58

.attr(‘id’, ‘foo’)

.val(“new val”)

.width()

.css(“top”)

Trang 59

.attr(‘id’, ‘foo’)

.val(“new val”)

.width()

.css(“top”) .css(“top”, “80px”)

Trang 60

.attr(‘id’, ‘foo’)

.val(“new val”)

.width() .width(60)

.css(“top”) .css(“top”, “80px”)

Trang 61

Attributes

Trang 62

$( ) css (“ border ”, “ 1px solid black ”); Set border to 1px black

Attributes

Trang 63

$( ) css (“ border ”, “ 1px solid black ”); Set border to 1px black

Set various css properties.

Trang 64

$( ) css (“ border ”, “ 1px solid black ”);

Set border to 1px black

Set various css properties.

Trang 66

$( ) html (“ <p>I’m new</p> ”);

Replace HTML with a new paragraph.

Attributes

Trang 67

$( ) html (“ <p>I’m new</p> ”);

Replace HTML with a new paragraph.

Attributes

<div>whatever</div> turns into

<div> <p>I’m new</p> </div>

Trang 68

$( ) html (“ <p>I’m new</p> ”);

Replace HTML with a new paragraph.

Set checkboxes attribute “checked” to checked.

$(“ :checkbox ”) attr (“ checked ”,” checked ”);

Attributes

<div>whatever</div> turns into

<div> <p>I’m new</p> </div>

Trang 69

$( ) html (“ <p>I’m new</p> ”);

Replace HTML with a new paragraph.

Set checkboxes attribute “checked” to checked.

$(“ :checkbox ”) attr (“ checked ”,” checked ”);

$( ) val (“ 3 ”);

Set input value to 3.

Attributes

<div>whatever</div> turns into

<div> <p>I’m new</p> </div>

Trang 70

$( ) html (“ <p>I’m new</p> ”);

Replace HTML with a new paragraph.

Set checkboxes attribute “checked” to checked.

$(“ :checkbox ”) attr (“ checked ”,” checked ”);

<div>whatever</div> turns into

<div> <p>I’m new</p> </div>

Trang 71

Events Examples

Trang 72

Events

Trang 73

$(“ button ”) click ( function(){

something();

} );

When a button is clicked, do something

Events

Trang 74

$(“ button ”) click ( function(){

something();

} );

When a button is clicked, do something

Setup a custom event and trigger it.

$(“ button “) bind (“ expand ”, function(){ something();

});

$(“ button:first “) trigger (“ expand ”);

Events

Trang 75

$(“ button ”) click ( function(){

something();

} );

When a button is clicked, do something

Setup a custom event and trigger it.

$(“ button “) bind (“ expand ”, function(){ something();

});

$(“ button:first “) trigger (“ expand ”);

Events

$(“ button “) unbind (“ expand ”);

Unbind custom event.

Trang 76

Event Delegation

Trang 77

$(“ button ”) live (‘ click ’, function(){

Trang 78

$(“ button ”) live (‘ click ’, function(){

something();

} );

Event Delegation

Attach events to document

Attach event delegation to elements

$(“ form “) delegate (“ button ”, ” click ”, function(){ something();

});

Trang 79

Effects / Animation

Examples

Trang 80

Animation / EffectsTypes of Effects

Trang 81

Animation / Effects

#1 Hide and ShowTypes of Effects

Trang 82

Animation / Effects

#2 Fade In and Out

#1 Hide and ShowTypes of Effects

Trang 83

Animation / Effects

#2 Fade In and Out

#1 Hide and Show

#3 Slide Up and Down Types of Effects

Trang 84

Animation / Effects

Trang 86

$(“ div:first ”) slideToggle ();

});

With each click, slide up / slide down a div.

Animate elements to 300px wide in 5 seconds.

$( ) animate ({ “ width ”: “ 300px ” }, 500 );

Animation / Effects

Trang 87

$(“ div:first ”) slideToggle ();

});

With each click, slide up / slide down a div.

Animate elements to 300px wide in 5 seconds.

Trang 88

Traversing Examples

Trang 96

Ajax Examples

Trang 97

Ajax Examples

Trang 98

$( ) get (“tag.php”, { “ bar ”: “ baz ” });

Post data, “bar” equals “baz” to tag.php using get.

Ajax Examples

Trang 99

$( ) get (“tag.php”, { “ bar ”: “ baz ” });

Post data, “bar” equals “baz” to tag.php using get.

Post data, “foo” equals “bar” to send.php, then

alert the response

$ post (“ send.php ”, { foo : ” bar ” },

function(response){

alert(response);

} );

Ajax Examples

Trang 100

Extending jQuery

Trang 103

<div> you used myPlugin! </div>

<div> you used myPlugin! </div>

</body>

</html>

$(“div”).myPlugin();

Plugin Example

Trang 104

Wait, There’s More!

Trang 105

jQuery isn’t only about simpler code

Trang 106

jQuery isn’t only about simpler code

Trang 107

jQuery isn’t only about simpler code

It is also about

Trang 108

jQuery isn’t only about simpler code

It is also about

great community

pluginsopen (free) license

speed

light weight code

Trang 109

+javascript,+mootools+javascript&ctab=0&geo=all&date=all&sort=1

Led to World Domination

jQuery

Trang 110

Usage Across Top 10,000 Sites

http://trends.builtwith.com/javascript

Trang 114

Video Training

Trang 115

Thank you!

Marc Grabanski:

http://marcgrabanski.com

Ngày đăng: 22/03/2014, 16:20

TỪ KHÓA LIÊN QUAN

TÀI LIỆU CÙNG NGƯỜI DÙNG

TÀI LIỆU LIÊN QUAN

🧩 Sản phẩm bạn có thể quan tâm