-
Notifications
You must be signed in to change notification settings - Fork 28
/
demo.html
160 lines (152 loc) · 4.47 KB
/
demo.html
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>jQuery Center Plugin Demo</title>
<style type="text/css">
h1{
text-align : center;
}
#wrap{
width: 880px;
margin: 0 auto 50px;
}
#info{
text-align: center;
margin: 50px 0 0;
}
#play-ground1{
height: 150px;
}
#play-ground2{
height: 220px;
position: relative;
}
.spacer{
height: 50px;
}
.parent{
width: 200px;
height: 200px;
position: relative;
background: #cccccc;
display: inline;
float: left;
margin: 0 20px 0 0;
}
.some-element{
width: 100px;
height: 100px;
position: absolute;
background: #333333;
color: white;
}
.btn{
background: #cccccc;
float: left;
display: inline;
font-family: arial;
font-size: 12px;
font-weight: bolder;
padding: 3px 7px;
margin: 0 8px 0 0;
cursor: pointer;
}
</style>
</head>
<body>
<div id="wrap">
<h1>
jQuery Center Plugin Demo
</h1>
<p>
Try clicking the buttons to see how they works :)
</p>
<h2>
centralize #some-element against the window
</h2>
<div id="sample1" class="spacer">
<div id="btn1" class="btn">Centralize</div>
<div class="btn restore">Restore</div>
</div>
<div id="play-ground1">
<div id="some-element" class="some-element">
#some-element
</div>
</div>
<h2>
centralize .some-element against its parent
</h2>
<div id="sample2" class="spacer">
<div id="btn2" class="btn">Centralize</div>
<div class="btn restore">Restore</div>
</div>
<div id="play-ground2">
<div class="parent">
.parent
<div class="some-element">
.some-element
</div>
</div>
<div class="parent">
.parent
<div class="some-element">
.some-element
</div>
</div>
<div class="parent">
.parent
<div class="some-element">
.some-element
</div>
</div>
<div class="parent">
.parent
<div class="some-element">
.some-element
</div>
</div>
</div>
<h3 id="info">
Demo provides by <a href="http://dreamerslab.com/">DreamersLab</a>
</h3>
</div>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script>
<script type="text/javascript" src="jquery.center.min.js"></script>
<script type="text/javascript" charset="utf-8">
// wrap everything in document ready event
$( function(){
// cache jquery obj
var $el = $( '#some-element' );
var $pg2el = $( '#play-ground2' ).find( '.some-element' );
// centerize '#some-element' against the window on clicking #btn1
$( '#btn1' ).bind( 'click', function(){
$el.center();
});
// restore '#some-element' position on clicking '.restore'
$( '#sample1' ).find( '.restore' ).bind( 'click', function(){
$el.attr( 'style', '' );
});
// centerize each '.some-element' against its parent on clicking #btn2
$( '#btn2' ).bind( 'click', function(){
$pg2el.center({ against: 'parent' });
});
// restore '.some-element' position on clicking '.restore'
$( '#sample2' ).find( '.restore' ).bind( 'click', function(){
$pg2el.attr( 'style', '' );
});
});
</script>
<script type="text/javascript" charset="utf-8">
// google analytics
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-20960410-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</body>
</html>