-
Notifications
You must be signed in to change notification settings - Fork 32
Durga js events #539
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Durga js events #539
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
|
|
||
| * { | ||
| margin: 0; | ||
| padding: 0; | ||
| box-sizing: border-box; | ||
| } | ||
|
|
||
| body { | ||
| font-family: Arial, sans-serif; | ||
| line-height: 1.6; | ||
| } | ||
|
|
||
| header { | ||
| background: #0d0a99; | ||
| color: #fff; | ||
| padding: 20px; | ||
| text-align: center; | ||
| } | ||
|
|
||
| nav ul { | ||
| list-style: none; | ||
| display: flex; | ||
| justify-content: center; | ||
| gap: 20px; | ||
| margin-top: 10px; | ||
| } | ||
|
|
||
| nav a { | ||
| color: #fff; | ||
| text-decoration: none; | ||
| } | ||
|
|
||
| main { | ||
| display: flex; | ||
| padding: 20px; | ||
| gap: 20px; | ||
| } | ||
|
|
||
| article { | ||
| flex: 3; | ||
| background: #2c13a8; | ||
| color: #fff; | ||
| padding: 20px; | ||
| border-radius: 8px; | ||
| } | ||
|
|
||
| aside { | ||
| flex: 1; | ||
| background: #4d119b; | ||
| color: #fff; | ||
| padding: 20px; | ||
| border-radius: 8px; | ||
| } | ||
|
|
||
| footer { | ||
| background: #3f12ba; | ||
| color: #fff; | ||
| text-align: center; | ||
| padding: 15px; | ||
| margin-top: 20px; | ||
| bottom: auto; | ||
| } | ||
|
|
||
| @media (max-width: 768px) { | ||
| main { | ||
| flex-direction: column; | ||
| flex:1; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
| <title>CSS Animation & Media Queries</title> | ||
| <style> | ||
| body { | ||
| font-family: Arial, sans-serif; | ||
| margin: 0; | ||
| padding: 0; | ||
| display: flex; | ||
| justify-content: center; | ||
| align-items: center; | ||
| height: 100vh; | ||
| background: #f0f0f0; | ||
| } | ||
| .box { | ||
| width: 150px; | ||
| height: 150px; | ||
| background: #3498db; | ||
| border-radius: 10px; | ||
| display: flex; | ||
| justify-content: center; | ||
| align-items: center; | ||
| color: white; | ||
| font-weight: bold; | ||
| animation: bounce 2s infinite; | ||
| } | ||
| @keyframes bounce { | ||
| 0%, 100% { | ||
| transform: translateY(0); | ||
| } | ||
| 50% { | ||
| transform: translateY(-50px); | ||
| } | ||
| } | ||
| @media (max-width: 768px) { | ||
| .box { | ||
| width: 120px; | ||
| height: 120px; | ||
| font-size: 14px; | ||
| background: #e67e22; | ||
| } | ||
| } | ||
|
|
||
| @media (max-width: 480px) { | ||
| .box { | ||
| width: 90px; | ||
| height: 90px; | ||
| font-size: 12px; | ||
| background: #2ecc71; | ||
| } | ||
| } | ||
| </style> | ||
|
Comment on lines
+7
to
+55
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The PR description checklist includes 'Avoid inline styles unless absolutely necessary.' and 'Use modular CSS files if applicable'. Placing CSS within a |
||
| </head> | ||
| <body> | ||
| <div class="box">Hello Guys..!</div> | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| </body> | ||
| </html> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
| <title>Event Delegation & Bubbling</title> | ||
| <link rel="stylesheet" href="style.css"> | ||
| </head> | ||
| <body> | ||
| <h2>Event Delegation and Bubbling Example</h2> | ||
| <table id="myTable"></table> | ||
|
|
||
| <script src="script.js"></script> | ||
| </body> | ||
| </html> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
|
|
||
| const table = document.getElementById("myTable"); | ||
| for (let i = 0; i < 10; i++) { | ||
| const row = table.insertRow(); | ||
| for (let j = 0; j < 10; j++) { | ||
| const cell = row.insertCell(); | ||
| cell.textContent = `${i + 1},${j + 1}`; // Display cell position | ||
| } | ||
| } | ||
| table.addEventListener("mouseover", (event) => { | ||
| if (event.target.tagName === "TD") { | ||
| const cell = event.target; | ||
| const row = cell.parentNode; | ||
| const colIndex = cell.cellIndex; | ||
|
|
||
| for (let td of row.children) { | ||
| td.classList.add("highlight"); | ||
| } | ||
|
|
||
| for (let r of table.rows) { | ||
| r.cells[colIndex].classList.add("highlight"); | ||
| } | ||
| } | ||
| }); | ||
|
|
||
| table.addEventListener("mouseout", (event) => { | ||
|
|
||
| if (event.target.tagName === "TD") { | ||
| for (let row of table.rows) { | ||
| for (let cell of row.cells) { | ||
| cell.classList.remove("highlight"); | ||
| } | ||
| } | ||
| } | ||
| }); | ||
|
Comment on lines
+26
to
+35
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The table.addEventListener("mouseleave", () => {
for (let row of table.rows) {
for (let cell of row.cells) {
cell.classList.remove("highlight");
}
}
}); |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| table { | ||
| border-collapse: collapse; | ||
| margin: 20px; | ||
| } | ||
|
|
||
| td { | ||
| border: 1px solid black; | ||
| padding: 10px; | ||
| width: 50px; | ||
| text-align: center; | ||
| cursor: pointer; | ||
| } | ||
|
|
||
| .highlight { | ||
| background-color: yellow; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <title>Keyboard Events Example</title> | ||
| <style> | ||
| body { | ||
| font-family: Arial, sans-serif; | ||
| text-align: center; | ||
| margin-top: 40px; | ||
| } | ||
|
|
||
| .box { | ||
| border: 2px solid black; | ||
| width: 400px; | ||
| margin: 20px auto; | ||
| padding: 20px; | ||
| font-size: 20px; | ||
| min-height: 50px; | ||
| } | ||
|
|
||
| .keydown { | ||
| background-color: lightblue; | ||
| } | ||
|
|
||
| .keyup { | ||
| background-color: lightgreen; | ||
| } | ||
| </style> | ||
| </head> | ||
| <body> | ||
| <h2>Keyboard Events: Keydown & Keyup</h2> | ||
| <div class="box keydown" id="keydownDiv">KeyDown Events:</div> | ||
| <div class="box keyup" id="keyupDiv">KeyUp Events:</div> | ||
|
|
||
| <script src="script.js"></script> | ||
| </body> | ||
| </html> |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,16 @@ | ||||||||||||||||||||||
| const keydownDiv = document.getElementById("keydownDiv"); | ||||||||||||||||||||||
| const keyupDiv = document.getElementById("keyupDiv"); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| let pressedKeys = new Set(); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| window.addEventListener("keydown", (event) => { | ||||||||||||||||||||||
| pressedKeys.add(event.key); | ||||||||||||||||||||||
| const combo = Array.from(pressedKeys).join(" + "); | ||||||||||||||||||||||
| keydownDiv.textContent = `KeyDown: ${combo}`; | ||||||||||||||||||||||
| }); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| window.addEventListener("keyup", (event) => { | ||||||||||||||||||||||
| pressedKeys.delete(event.key); | ||||||||||||||||||||||
| keyupDiv.textContent = `KeyUp: ${event.key}`; | ||||||||||||||||||||||
| }); | ||||||||||||||||||||||
|
Comment on lines
+13
to
+16
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The
Suggested change
|
||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <title>Event Propagation Example</title> | ||
| <link rel="stylesheet" href="style.css"> | ||
| </head> | ||
| <body> | ||
| <h2>Event Propagation: Capture, Target, and Bubble</h2> | ||
|
|
||
| <div id="level1"> | ||
| Level 1 | ||
| <div id="level2"> | ||
| Level 2 | ||
| <div id="level3"> | ||
| Level 3 (Click Me) | ||
| </div> | ||
| </div> | ||
| </div> | ||
|
|
||
| <script src="script.js"></script> | ||
| </body> | ||
| </html> |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,15 @@ | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| const level1 = document.getElementById("level1"); | ||||||||||||||||||||||||||||||||||||||||||||||
| const level2 = document.getElementById("level2"); | ||||||||||||||||||||||||||||||||||||||||||||||
| const level3 = document.getElementById("level3"); | ||||||||||||||||||||||||||||||||||||||||||||||
| level1.addEventListener("click", () => { | ||||||||||||||||||||||||||||||||||||||||||||||
| alert("Level 1 (Capture Phase)"); | ||||||||||||||||||||||||||||||||||||||||||||||
| }, true); | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| level2.addEventListener("click", () => { | ||||||||||||||||||||||||||||||||||||||||||||||
| alert("Level 2 (Bubble Phase)"); | ||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| level3.addEventListener("click", () => { | ||||||||||||||||||||||||||||||||||||||||||||||
| alert("Level 3 (Target Phase)"); | ||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+5
to
+15
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| #level1, #level2, #level3 { | ||
| padding: 40px; | ||
| margin: 10px; | ||
| border: 2px solid black; | ||
| text-align: center; | ||
| font-weight: bold; | ||
| cursor: pointer; | ||
| } | ||
|
|
||
| #level1 { | ||
| background-color: #ffd6d6; | ||
| } | ||
|
|
||
| #level2 { | ||
| background-color: #d6ffd6; | ||
| } | ||
|
|
||
| #level3 { | ||
| background-color: #d6d6ff; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
| <title>Prevent Default Example</title> | ||
| <style> | ||
| form { | ||
| margin: 20px; | ||
| padding: 20px; | ||
| border: 1px solid #ccc; | ||
| width: 300px; | ||
| border-radius: 10px; | ||
| } | ||
| input { | ||
| display: block; | ||
| margin-bottom: 10px; | ||
| padding: 8px; | ||
| width: 90%; | ||
| } | ||
| #message { | ||
| margin-top: 10px; | ||
| font-weight: bold; | ||
| color: red; | ||
| } | ||
| </style> | ||
| </head> | ||
| <body> | ||
|
|
||
| <form id="myForm"> | ||
| <label>Name:</label> | ||
| <input type="text" id="name" placeholder="Enter your name"> | ||
|
|
||
| <label>Email:</label> | ||
| <input type="email" id="email" placeholder="Enter your email"> | ||
|
|
||
| <button type="submit">Submit</button> | ||
| </form> | ||
|
|
||
| <p id="message"></p> | ||
|
|
||
| <script src="script.js"></script> | ||
|
|
||
| </body> | ||
| </html> |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,12 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| document.getElementById("myForm").addEventListener("submit", function(event) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| const name = document.getElementById("name").value.trim(); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| const email = document.getElementById("email").value.trim(); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| const message = document.getElementById("message"); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| if (name === "" || email === "") { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| event.preventDefault(); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| message.textContent = "Please fill out all fields before submitting!"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| message.style.color = "green"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| message.textContent = "Form submitted successfully!"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+1
to
+12
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The form submission is not prevented on success, which causes the page to reload immediately. As a result, the user will never see the 'Form submitted successfully!' message. A better pattern is to call
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,12 @@ | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| const parentDiv = document.getElementById("parentDiv"); | ||||||||||||||||||||||||||||||||||
| const childDiv = document.getElementById("childDiv"); | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| parentDiv.addEventListener("click", function() { | ||||||||||||||||||||||||||||||||||
| alert("Parent div clicked!"); | ||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| childDiv.addEventListener("click", function(event) { | ||||||||||||||||||||||||||||||||||
| alert("Child div clicked!"); | ||||||||||||||||||||||||||||||||||
| event.stopPropagation(); | ||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+5
to
+12
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using
Suggested change
|
||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
flex: 1property here has no effect because its parent element,<body>, does not havedisplay: flex. This line is redundant and can be removed. Also, there should be a space between the property and value for consistency (flex: 1).