当前位置:
文档之家› jQuery基础教程(第四版)课后练习4
jQuery基础教程(第四版)课后练习4
21switch (event.which) {
22case 37:
23$box.animate({'left': '-=20px'}, 'fast');
24break;
25case39:……
26case38:……
27case 40:
28$box.animate({'top': '+=20px'}, 'fast');
4$(this).css('backgroundColor', 'yellow');
5}, function() {
6$(this).css('backgroundColor', style1);
7// $(this).removeClass('hover');
8})
(3)单击标题(<h2>)使其不透明度变为25%,同时添加20px的左外边距,当这两个效果完成后,把讲话文本变成50%的不透明度9;h2').click(function() {
10$(this).animate({
11'opacity': 0.25,
12'margin-left': '+=20px'
13}, 'slow');
14$('.speech').animate({
15'opacity': 0.5
16}, 'slow');
17})
(4)挑战:按下方向键时,使样式转换器向相应的方向平滑移动20像素;四个方向键的键码分别是37(左)、38(上)、39(右)和40(下)。
18$(document).keyup(function(event) {
19var$box = $('#switcher');
20$box.css('position', 'relative');
jQuery
CHAP
(1)修改样式表,一开始先隐藏页面内容,当页面加载后,慢慢地淡入内容;
$('body').hide().fadeIn(2000);
(2)在鼠标悬停到段落上面时,给段落应用黄色背景;
1varstyle1;
2$('p').hover(function() {
3style1 = $(this).css('backgroundColor');