Browse Source

add hw DOM

Mitrofanova Natali 3 years ago
parent
commit
580805d702
3 changed files with 213 additions and 0 deletions
  1. 49 0
      HW 7 DOM/index.html
  2. 86 0
      HW 7 DOM/script.js
  3. 78 0
      HW 7 DOM/style.css

+ 49 - 0
HW 7 DOM/index.html

@@ -0,0 +1,49 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <meta http-equiv="X-UA-Compatible" content="IE=edge">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title>Document</title>
+    <link rel="stylesheet" href="style.css"><link
+</head>
+<body>
+    <div class="wrapper"></div>
+
+    <!-- Calc  -->
+    <div id="wrapperCalc">
+        <p>TASK "CALC" : "Рассчет нормы веса для человека"</p>
+
+        <p>Выберите пол :</p>
+        <div>
+        <input type="radio" id="man" name="sex" value="male">Мужчина
+        
+        </div>
+        <div>
+        <input type="radio" id="woman" name="sex" value="female">Женщина
+        
+        </div>
+        
+        <p>Введите ваш рост в см:</p>
+        <input id="input1" type="number" value="170">
+        <button id="btnResult">Рассчитать</button>
+        <span id="result"></span>
+    
+    </div>
+    
+    <!-- Calc Live  -->
+    <p class="task">TASK "CALC LIVE" : "Конвертер км в мили"</p>
+    <div id="wrapperCalcLive">
+        <div>
+        <p>км</p>
+        <input id="km" type="number" value="1">
+        </div>
+        <p class="equal">=</p>
+        <div>
+        <p></p>миль</p>
+        <input type="number" id="mile" value="0.62">
+    </div>
+
+    <script src="script.js"></script>
+</body>
+</html>

+ 86 - 0
HW 7 DOM/script.js

@@ -0,0 +1,86 @@
+// Task 1 Таблица умножения
+
+const wrapper = document.querySelector(".wrapper");
+const table = document.createElement("table");
+wrapper.appendChild(table);
+
+for (let i=0; i<10; i++){
+    const line = document.createElement("tr");
+    table.appendChild(line);
+
+    for(let j=0; j<10; j++){
+        const cell = document.createElement("td");
+        cell.innerText = `${i*j}`;
+        line.appendChild(cell);
+        if(i==0){
+            cell.innerText= `${j}`;
+        }else
+        if (j==0){
+            cell.innerText= `${i}`;
+        }
+    }
+}
+
+
+// Task 2 Подсветить ячейку
+// +
+// Task 3 Подсветить строку и столбец
+
+const tdList = document.querySelectorAll("td");
+
+tdList.forEach((el)=>{
+    el.addEventListener("mouseover",changeColor);
+    el.addEventListener("mouseout",changeColor);
+});
+
+function changeColor(){
+    // подсветить ячейку
+    // this.style.backgroundColor = this.style.backgroundColor ? "" : "green";  
+
+    console.log(this.parentElement.rowIndex);
+    feelColor(this.parentElement.rowIndex, this.cellIndex)
+}
+function feelColor(trIndex, tdIndex){
+    const trArr = document.querySelectorAll("tr");
+    trArr[trIndex].style.backgroundColor = trArr[trIndex].style.backgroundColor ? "" : "pink";
+    for(let i=0; i<trArr.length; i++){
+        const tdArr = trArr[i].querySelectorAll("td");
+        tdArr[tdIndex].style.backgroundColor = tdArr[tdIndex].style.backgroundColor ? "" : "pink";
+    }
+
+}
+
+
+// Task Calc 
+
+const height = document.getElementById("input1");
+let sex = document.getElementsByName("sex");
+const calcBtn = document.getElementById("btnResult");
+const result = document.getElementById("result")
+
+calcBtn.addEventListener("click",checkBoxHandler);
+
+function checkBoxHandler(){
+    let factor = 0;
+
+    for (let i=0; i<sex.length; i++){
+        factor = sex[0].checked ?  90 : 110;
+    }
+    result.innerText = `Ваша норма веса ${Number(height.value)-factor} кг`
+
+}
+
+
+// Task Calc Live
+const km = document.getElementById("km");
+const mile = document.getElementById("mile");
+km.addEventListener("input", convertKm);
+mile.addEventListener("input", convertMile);
+
+function convertKm(){
+    mile.value = (Number(km.value) / 1.609).toFixed(2);
+    
+}
+function convertMile(){
+    km.value = (Number(mile.value) * 1.609).toFixed(2);
+}

+ 78 - 0
HW 7 DOM/style.css

@@ -0,0 +1,78 @@
+html{
+    margin: 0;
+    width: 100vw;
+    height: 100vh;
+}
+
+body{
+    margin: 0;
+    width: 100%;
+    height: 100%;
+}
+.wrapper{
+    width: fit-content;
+    height: fit-content;
+    margin-left: 50px;
+    
+}
+tr{
+    display: flex;
+}
+
+th, td{
+    width: 50px;
+    height: 50px;
+    border: 1px solid grey;
+    display: flex;
+    align-items: center;
+    justify-content: center;
+}
+
+#wrapperCalc{
+margin: 20px;
+display: flex;
+flex-direction: column;
+width: 400px;
+align-items: center;
+}
+input{
+    margin-top: 10px;
+    text-align: center;
+    padding: 5px;
+    font-size: 20px;
+    color: lightslategray;
+}
+input[type="number"]::-webkit-outer-spin-button,
+input[type="number"]::-webkit-inner-spin-button {
+    -webkit-appearance: none;
+    margin: 0;
+}
+button{
+    margin: 10px;
+    width: 100px;
+    font-size: 15px;
+    padding: 0;
+}
+span{
+    border-bottom: 1px solid grey;
+    width: 260px;
+    height: 30px;
+    font-size: 20px;
+    display: flex;
+    align-items: center;
+    justify-content: center;
+}
+#wrapperCalcLive{
+    display: flex;
+    margin: 50px;
+    padding-bottom: 100px;
+    max-width: 600px;
+    font-size: 20px;
+}
+.task{
+
+    margin: 50px;
+}
+.equal{
+    padding: 60px 20px;
+}