html音乐唱片自动转,css3animation模仿百度音乐的唱片旋转效果

好久没更新blog,补上几篇技术性的文章。好吧,第一篇是关于css3动画animation的使用,要用到keyframes规则。

1978fd90023dbc0afce328d86664e48d.png  

86b6678654089ceafb6ab317cd59ae3c.png

1

2

3

4

5

Document

6

7

8 $(function(){

9 /*$('.wrap').children('i').click(function(){

10 $(this).toggleClass('action');

11 if($(this).prev().css('-webkit-animation-play-state') == 'paused'){

12 $(this).prev().css({

13 '-webkit-animation-play-state':'running'

14 });

15 }else{

16 $(this).prev().css({

17 '-webkit-animation-play-state':'paused'

18 });

19 }

20 if($(this).prev().css('-moz-animation-play-state') == 'paused'){

21 $(this).prev().css({

22 '-moz-animation-play-state':'running'

23 });

24 }else{

25 $(this).prev().css({

26 '-moz-animation-play-state':'paused'

27 });

28 }

29 });*/

30 $('.wrap>i').click(function(){

31 $(this).toggleClass('action');

32 $(this).prev().toggleClass('pause');

33 });

34

35 });

36

37

38 .wrap{

39 width:120px;

40 height:120px;

41 position:relative;

42 }

43 .avatar-pic{

44 width:120px;

45 height:120px;

46 border-radius:50%;

47 overflow:hidden;

48 display:block;

49 cursor:default;

50 }

51 .wrap>i{

52 position:absolute;

53 top:42px;

54 left:42px;

55 width:36px;

56 height:36px;

57 outline:none;

58 border-radius:50%;

59 cursor:pointer;

60 }

61 .wrap>i:hover{

62 background-color:rgba(0,0,0,.4);

63 }

64 .zantin{

65 background:url(icons_bds.png) no-repeat 0px -408px;

66 }

67 .action{

68 background:url(icons_bds.png) no-repeat -96px -408px;

69 }

70

71

72

73 .avatar{

74 animation:rotator 10s linear infinite;

75 -webkit-animation:rotator 10s linear infinite;

76 -moz-animation:rotator 10s linear infinite;

77 -o-animation:rotator 10s linear infinite;

78 -ms-animation:rotator 10s linear infinite;

79

80 -webkit-animation-play-state:running;

81 -moz-animation-play-state:running;

82 -o-animation-play-state:running;

83 -ms-animation-play-state:running;

84 animation-play-state:running;

85 }

86 .pause{

87 animation-play-state:paused;

88 -webkit-animation-play-state:paused;

89 -moz-animation-play-state:paused;

90 -o-animation-play-state:paused;

91 -ms-animation-play-state:paused;

92 }

93

94 @keyframes rotator{

95 from{transform:rotate(0deg);}

96 to{transform:rotate(360deg);}

97 }

98 @-webkit-keyframes rotator{

99 form{-webkit-transform:rotate(0deg);}

100 to{-webkit-transform:rotate(360deg);}

101 }

102 @-moz-keyframes rotator{

103 form{-moz-transform:rotate(0deg);}

104 to{-moz-transform:rotate(360deg);}

105 }

106 @-o-keyframes rotator{

107 form{-o-transform:rotate(0deg);}

108 to{-o-transform:rotate(360deg);}

109 }

110 @-ms-keyframes rotator{

111 form{-ms-transform:rotate(0deg);}

112 to{-ms-transform:rotate(360deg);}

113 }

114

115

116

117

118

119 haha

120

121

122

123

124

css3看起来非常美好,但是实际使用中还是存在不少的不确定性。如果不能看到已经实现的代码模板,你很难确信自己的代码格式就一定正确。所以你可以到http://daneden.me/animate/来观察各种动画效果,选择自己喜欢的动画并生成代码,下载下来后再按照自己的需求来编写动画代码。这样会让你的动画效果实现起来事半功倍(不要担心它达不到你的要求,上面有很多的效果,你可以自己组合,只要你的想象力够丰富)。

来源:https://www.cnblogs.com/hl-520/p/4363122.html

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
你可以使用HTML5中的<canvas>元素来绘制旋转唱片。以下是一个示例: ```html <!DOCTYPE html> <html> <head> <title>旋转唱片</title> <style> canvas { border: 1px solid black; } </style> </head> <body> <canvas id="myCanvas" width="200" height="200"></canvas> <script> var canvas = document.getElementById("myCanvas"); var context = canvas.getContext("2d"); // 绘制黑色圆盘 context.beginPath(); context.arc(100, 100, 80, 0, 2 * Math.PI); context.fillStyle = "black"; context.fill(); // 绘制唱针 context.beginPath(); context.moveTo(100, 100); context.lineTo(120, 60); context.lineWidth = 5; context.strokeStyle = "white"; context.stroke(); // 定义旋转函数 var rotateDegree = 0; function rotate() { rotateDegree += 5; context.save(); context.clearRect(0, 0, canvas.width, canvas.height); context.translate(100, 100); context.rotate(rotateDegree * Math.PI / 180); context.translate(-100, -100); context.beginPath(); context.arc(100, 100, 80, 0, 2 * Math.PI); context.fillStyle = "black"; context.fill(); context.beginPath(); context.moveTo(100, 100); context.lineTo(120, 60); context.lineWidth = 5; context.strokeStyle = "white"; context.stroke(); context.restore(); requestAnimationFrame(rotate); } // 启动旋转 rotate(); </script> </body> </html> ``` 这个示例中,我们使用<canvas>元素绘制了一个黑色圆盘和一个唱针。然后定义了一个旋转函数,每次旋转5度,并且使用requestAnimationFrame函数定时调用该函数。在旋转函数中,我们使用context.save()和context.restore()保存和恢复画布状态,这样就不会影响到其他元素的绘制。通过使用context.translate()和context.rotate()函数,我们让画布绕着中心点旋转

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值