-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJQuery.html
More file actions
233 lines (187 loc) · 6.34 KB
/
Copy pathJQuery.html
File metadata and controls
233 lines (187 loc) · 6.34 KB
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
$(document).ready(function () {
console.log("Hello world");
$("button").click(function () {
$("#p1").fadeOut(2000);
});
$("p").click(function () {
console.log("U clicked me");
// $(this).fadeOut(2000);
// $(this).fadeIn();
$(this).hide();
});
//Using mouse enter and mouse leave
$("P").on({
mouseenter: function () {
$(this).css("background-color", "yellow");
},
mouseleave: function () {
$(this).css("background-color", "white");
},
});
//Using FadeIn feature
$("#btn1").click(function () {
$("#p1").fadeIn(2000);
});
//Slide toggling feature
$("#sldDownbtn").click(function () {
console.log("Inide slider");
$("#dynbtn").slideToggle(3000);
});
//Animate method intro
/*Is it possible to manipulate ALL CSS properties with the animate() method?
Yes, almost! However, there is one important thing to remember: all property names must be camel-cased when used with the animate() method: You will need to write paddingLeft instead of padding-left, marginRight instead of margin-right, and so on.
Also, color animation is not included in the core jQuery library.
If you want to animate color, you need to download the Color Animations plugin from jQuery.com.*/
//Animate function
$("#animateRect").click(function () {
console.log("Inside animater");
$("#rect").animate({ left: "250", top: "250" });
});
//Using += directly to add value to the height and width
$("#rect").mouseenter(function () {
$(this).animate({
padding: "100",
height: "+=200",
width: "+=200",
opacity: "0.125",
});
});
$("#rect").mouseleave(function () {
$(this).animate({
padding: "0",
height: "100",
width: "100",
left: "0",
top: "0",
opacity: "0.90",
});
});
//Using toggle directly in height property of animate function
$("#animateredRect").click(function(){
// $("#redRect").animate({
// height:'toggle'
// });
var rect=$("#rect");
var redRect=$("#redRect");
rect.animate({
height:'toggle'
},2000);
redRect.animate({
width:'toggle'
});
});
//Animate function
$("#animateredRect2").click(function(){
$("#redRect2").animate({
height:'toggle'
},5000);
});
//Stopping an animation in the middle
$("#stopBtn").click(function(){
$("#redRect2").stop();
});
//Chaining multiple functions together
$("#greenRect").click(function(){
$(this).css("background","yellow").slideUp(2000).slideDown(3000);
//$(this).css("background","#ff0000");
});
/*Three simple, but useful, jQuery methods for DOM manipulation are:
text() - Sets or returns the text content of selected elements
html() - Sets or returns the content of selected elements (including HTML markup)
val() - Sets or returns the value of form fields*/
//Get attribute property using attr function
$("#attrdemo").click(function(){
var greenRectHeight=$("#greenRect").attr("style");
console.log("Greenrect height ",greenRectHeight);
alert("Height of green rectangle is "+greenRectHeight);
});
var aRectanglesStyle="";
$("div").dblclick(function(){
console.log("aRectanglesStyle",aRectanglesStyle);
aRectanglesStyle=$(this).attr("style");
console.log("aRectanglesStyle",aRectanglesStyle);
});
//Setting a atrribute using jquery
$("div").mouseenter(function(){
if(aRectanglesStyle===""){
console.log("Empty property should not be assigned");
}
else{
console.log("Inside on mouse enter function of div");
$(this).attr("style",aRectanglesStyle);
aRectanglesStyle="";
console.log("aRectanglesStyle value reset",aRectanglesStyle);
}
});
//For adding such as using append ,prepend, after , before in jQuery use this page for reference
// https://www.w3schools.com/jquery/jquery_dom_add.asp
//For Removing elements you can use this one....
// https://www.w3schools.com/jquery/jquery_dom_remove.asp
});
</script>
</head>
<body>
<p id="p1" style="width: fit-content">This is paragraph1</p>
<p>Click me for effect</p>
<button>Button</button>
<button id="btn1">FadeIn</button>
<button id="sldDownbtn">Click me to slide Down a button</button>
<button height="200" width="200" id="dynbtn">
Dynamically generated button
</button>
<button id="animateRect">Click to animate the rectangle</button>
<button id="animateredRect">Toggle red React</button>
<!-- a rectangle -->
<div
id="rect"
style="
background: #98bf21;
height: 100px;
width: 100px;
position: relative;
"
></div>
<!-- a red rectangle -->
<div
id="redRect"
style="
background: #e74444;
height: 100px;
width: 100px;
position: relative;
"
></div>
<br/>
<br/>
<button id="stopBtn">stop animation</button>
<button id="animateredRect2">Animate red rect 2</button>
<div
id="redRect2"
style="
background: #368d20;
height: 100px;
width: 100px;
position: relative;
"
></div>
<!-- A Green rectangle -->
<!-- a red rectangle -->
<br/>
<p>A new green rectangle</p>
<div
id="greenRect"
style="
background: #cddb09;
height: 100px;
width: 100px;
position: relative;
"
></div>
<br />
<button id="attrdemo">Height of greenRect</button>
</body>
</html>