我是靠谱客的博主 可靠电灯胆,这篇文章主要介绍学习笔记:《jQuery基础教程》第四版第四章课后练习——样式与动画,现在分享给大家,希望可以做个参考。

1、修改样式表,一开始先隐藏页面内容,当页面加载后,慢慢地淡入内容。

复制代码
1
2
3
4
$(document).ready(function() { $('body').css('display', 'none'); $('body').fadeIn(1500);//自行设置时间 });

2、在鼠标悬停到段落上面时,给段落应用黄色背景。

复制代码
1
2
3
4
5
6
7
8
$(document).ready(function() { $('p').mouseover(function(){ $(this).css('backgroundColor', 'yellow'); });//当鼠标移动到段落上时段落背景应用黄色。 $('p').mouseout(function(){ $(this).css('backgroundColor', 'white'); });//当鼠标移出段落上时段落背景应用白色。 });

3、单击标题(<h2>)使其不透明度变为25%,同时添加20px的左外边距,当这两个效果完成后,把讲话文本变成50%的不透明度。

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
$(document).ready(function() { $('h2').click(function(){ $(this) .fadeTo('slow', 0.25) .animate({ paddingLeft: '+=200' + 'px'//或者paddingLeft: '+=200px' },{ duration: 'slow', queue: false }) .queue(function(next){ $('div.speech').fadeTo('slow', 0.5) }); }); });

4、挑战:按下方向键时,使样式转换器向相应的方向平滑移动20像素;四个方向键的键码分别是37(左)、38(上)、39(右)、40(下)。

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
var key_left = 37; var key_up = 38; var key_right = 39; var key_down = 40; var $switcher = $('#switcher'); $switcher.css('position', 'relative'); $(document).keyup(function(event){ switch(event.which){ case key_left: $switcher .animate({ left: '-=20px' },{ duration: 'fast' }) break; case key_up: $switcher .animate({ top: '-=20px' },{ duration: 'fast' }) break; case key_right: $switcher .animate({ left: '+=20px' },{ duration: 'fast' }) break; case key_down: $switcher .animate({ top: '+=20px' },{ duration: 'fast' }) } });

效果请点击

最后

以上就是可靠电灯胆最近收集整理的关于学习笔记:《jQuery基础教程》第四版第四章课后练习——样式与动画的全部内容,更多相关学习笔记内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(57)

评论列表共有 0 条评论

立即
投稿
返回
顶部