首頁 > web前端 > js教程 > 基於jQuery實作Div視窗震動特效程式碼-程式碼簡單_jquery

基於jQuery實作Div視窗震動特效程式碼-程式碼簡單_jquery

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
發布: 2016-05-16 15:41:49
原創
1435 人瀏覽過

這是一款jQuery視窗震動效果程式碼,在Div邊框內點擊一下滑鼠,它就開始震動了,適用瀏覽器:IE8、360、FireFox、Chrome、Opera、傲遊、搜狗、世界之窗等。

效果圖如下:

程式碼如下:

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

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

<title>jquery窗口震动特效</title>

<script type="text/javascript" src="http://www.jb51.net/ajaxjs/jquery-1.6.2.min.js"></script>

<script type="text/javascript">

;(function($){

var element = {};

$.fn.jshaker = function(){

element = $(this);

element.css(position, relative);

element.find(*).each(function(i, el){

$(el).css(position, relative);

});

var iFunc = function(){ $.fn.jshaker.animate($(element)); };

setTimeout(iFunc, 50);

};

$.fn.jshaker.animate = function(el){

$.fn.jshaker.shake(el);

el.find(*).each(function(i, el){

$.fn.jshaker.shake(el);

});

var iFunc = function(){ $.fn.jshaker.animate(el); };

setTimeout(iFunc, 50);

}

$.fn.jshaker.shake = function(el){

var pos = $(el).position();

if(Math.random() > 0.5){

$(el).css(top, pos[top] + Math.random() * 20 < 10 &#63; (Math.random() * 20 * (-1)) : Math.random() * 20);

} else {

$(el).css(left, pos[left] + Math.random() * 20 < 10 &#63; (Math.random() * 20 * (-1)) : Math.random() * 20);

}

}

})(jQuery);

</script>

<script type="text/javascript">

$(document).ready(function(){

$(.block).click(function(){

$(this).jshaker();

});

});

</script>

<style type="text/css">

BODY{font-family: "Lucida Grande", Arial, Helvetica, sans-serif;color: #666666;font-size: 12px;background: #FFFFFF;}

A{color: #0A8ECC;}

A: HOVER{text-decoration: none;color: #8FCB2F;}

H1{font-weight: normal;color: #0A8ECC;margin: 0;padding: 0;}

BODY{margin: 20px;padding: 20px;}

STRONG{color: #000000;}

.vspacer{height: 20px;}

PRE.code{padding: 7px;background: #777777;color: #F0F0F0;width: 400px;overflow: auto;}

#content-area{border: 3px solid #CCCCCC;background: #F0F0F0;padding: 10px;width: 500px;}

P.script-link{clear: both;padding: 10px 0;border-top: 1px dotted #CCCCCC;}

#content .block {float: left;border: 1px solid #CCCCCC;background: #F0F0F0;padding: 10px;margin: 10px;width: 300px;}

</style>

</head>

<body>

<div id="page">

<h1>jquery窗 口 震 动 特 效</h1>

<div id="content">

<div class="block">

<p>点击本框内,可实现震动</p>

<ul>

<li>Item 1</li>

<li>Item 2</li>

<li>

Item 3

<ul>

<li>Sub Item 1</li>

<li>Sub Item 2</li>

<li>Sub Item 3</li>

<li>Sub Item 4</li>

<li>Sub Item 5</li>

</ul>

</li>

<li>Item 4</li>

<li>Item 5</li>

</ul>

</div>

<div class="block">

<form action="#">

<p><label for="inp1">Text Field 1:</label><input type="text" name="inp1" id="inp1" value="" /></p>

<p><label for="inp2">Text Field 2:</label><input type="text" name="inp2" id="inp2" value="" /></p>

<p><button type="submit">Submit</button></p>

</form>

</div>

</div>

<p class="script-link">

</p>

</div>

</body>

</html>

登入後複製

以上程式碼很簡單吧,基於jquery實現div窗口震動的特效就製作出來了,小夥伴們趕緊下載使用吧。

本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板