hw7.js 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. // Таблица умножения ===========================================================================
  2. const table = document.createElement('table')
  3. document.body.append(table)
  4. Object.assign(table.style, {width: '435px', height: '385px'})
  5. for (let i=0; i<10; i++){
  6. const tr = document.createElement('tr')
  7. table.appendChild(tr)
  8. for(let j=0; j<10; j++){
  9. const td = document.createElement('td')
  10. Object.assign(td.style, {border: '1px solid', borderColor: '#e1e1e3', textAlign: 'center', width: '20px'})
  11. tr.appendChild(td)
  12. let mTable = i*j
  13. mTable= mTable? mTable: j||i
  14. i%2? td.style.backgroundColor='#f8f8f8': td.style.backgroundColor='#ffffff'
  15. td.innerText=mTable
  16. }
  17. }
  18. // Подсветить ячейку ===========================================================================
  19. const table = document.createElement('table')
  20. document.body.append(table)
  21. Object.assign(table.style, {width: '435px', height: '385px'})
  22. for (let i=0; i<10; i++){
  23. const tr = document.createElement('tr')
  24. table.appendChild(tr)
  25. for(let j=0; j<10; j++){
  26. const td = document.createElement('td')
  27. Object.assign(td.style, {border: '1px solid', borderColor: '#e1e1e3', textAlign: 'center', width: '20px'})
  28. tr.appendChild(td)
  29. let mTable = i*j
  30. mTable? mTable===0: mTable = j||i
  31. i%2? td.style.backgroundColor='#f8f8f8': td.style.backgroundColor='#ffffff'
  32. td.innerText=mTable
  33. td.onmouseover = function(){
  34. this.style.backgroundColor='#ffba00'
  35. }
  36. td.onmouseout = function(){
  37. i%2? td.style.backgroundColor='#f8f8f8': td.style.backgroundColor='#ffffff'
  38. }
  39. }
  40. }
  41. // Подсветить строку и столбец ===========================================================================
  42. const table = document.createElement('table')
  43. document.body.append(table)
  44. Object.assign(table.style, {width: '435px', height: '385px'})
  45. for (let i=0; i<10; i++){
  46. const tr = document.createElement('tr')
  47. table.appendChild(tr)
  48. for(let j=0; j<10; j++){
  49. const td = document.createElement('td')
  50. Object.assign(td.style, {border: '1px solid', borderColor: '#e1e1e3', textAlign: 'center', width: '20px'})
  51. tr.appendChild(td)
  52. let mTable = i*j
  53. mTable? mTable===0: mTable = j||i
  54. i%2? td.style.backgroundColor='#e9e9e9': td.style.backgroundColor='#ffffff'
  55. td.innerText=mTable
  56. td.onmouseover = function(){
  57. td.style.backgroundColor='#d0bf55'
  58. tr.firstChild.style.backgroundColor='#6768ab'
  59. table.firstChild.children[j].style.backgroundColor='#6768ab'
  60. }
  61. td.onmouseout = function(){
  62. i%2? td.style.backgroundColor='#e9e9e9': td.style.backgroundColor='#ffffff'
  63. i%2? tr.firstChild.style.backgroundColor='#e9e9e9': tr.firstChild.style.backgroundColor='#ffffff'
  64. table.firstChild.children[j].style.backgroundColor='#ffffff'
  65. }
  66. }
  67. }
  68. // Либо =================================
  69. const table = document.createElement('table')
  70. document.body.append(table)
  71. Object.assign(table.style, {width: '435px', height: '385px'})
  72. for (let i=0; i<10; i++){
  73. const tr = document.createElement('tr')
  74. table.appendChild(tr)
  75. for(let j=0; j<10; j++){
  76. const td = document.createElement('td')
  77. Object.assign(td.style, {border: '1px solid', borderColor: '#e1e1e3', textAlign: 'center', width: '20px'})
  78. tr.appendChild(td)
  79. let mTable = i*j
  80. mTable = mTable? mTable: j||i
  81. i%2? td.style.backgroundColor='#e9e9e9': td.style.backgroundColor='#ffffff'
  82. td.innerText=mTable
  83. td.onmouseover = function(){
  84. td.style.backgroundColor='#d0bf55'
  85. for(let k=0; k<10; k++){
  86. td.parentElement.children[k].style.backgroundColor='#6768ab'
  87. td.style.backgroundColor='#d0bf55'
  88. }
  89. for(let l=0; l<table.children.length; l++){
  90. table.children[l].children[td.cellIndex].style.backgroundColor='#6768ab'
  91. td.style.backgroundColor='#d0bf55'
  92. }
  93. }
  94. td.onmouseout = function(){
  95. i%2? td.style.backgroundColor='#e9e9e9': td.style.backgroundColor='#ffffff'
  96. for(let k=0; k<10; k++){
  97. i%2?td.parentElement.children[k].style.backgroundColor='#e9e9e9': td.parentElement.children[k].style.backgroundColor='#ffffff'
  98. }
  99. for(let l=0; l<table.children.length; l++){
  100. l%2? table.children[l].children[td.cellIndex].style.backgroundColor='#e9e9e9': table.children[l].children[td.cellIndex].style.backgroundColor='#ffffff'
  101. }
  102. }
  103. }
  104. }
  105. // Calc ===========================================================================
  106. const div = document.createElement('div')
  107. document.body.append(div)
  108. Object.assign(div.style,
  109. {
  110. width:'500px',
  111. height:'175px',
  112. backgroundColor:'#e1ebf1',
  113. display:'flex',
  114. justifyContent:'center',
  115. flexDirection: 'column',
  116. alignItems:'center'
  117. })
  118. const h1 = document.createElement('h1')
  119. div.appendChild(h1)
  120. h1.innerText= 'КОНВЕРТИРОВАНИЕ ЗНАЧЕНИЙ ИЗ PX В EM'
  121. Object.assign(h1.style,
  122. {
  123. fontSize:'17px',
  124. textAlign:'center',
  125. fontFamily:'Helvetica',
  126. color:'#273648',
  127. margin:'0'
  128. })
  129. const inPut = document.createElement('input')
  130. inPut.id='input'
  131. inPut.type='number'
  132. inPut.placeholder='Введите значение в PX'
  133. div.appendChild(inPut)
  134. Object.assign(inPut.style,
  135. {
  136. width:'250px',
  137. height:'25px',
  138. border:'1px solid',
  139. borderColor:'white',
  140. marginTop:'15px',
  141. textAlign:'center'
  142. })
  143. const buttON = document.createElement('button')
  144. buttON.id='button'
  145. div.appendChild(buttON)
  146. Object.assign(buttON.style,
  147. {
  148. width:'100px',
  149. height:'30px',
  150. marginTop:'15px',
  151. backgroundColor:'#273648',
  152. border:'3px solid',
  153. borderColor:'white',
  154. cursor:'pointer',
  155. })
  156. const paragraph = document.createElement('p')
  157. buttON.appendChild(paragraph)
  158. paragraph.innerText='КОНВЕРТИРОВАТЬ'
  159. Object.assign(paragraph.style,
  160. {
  161. fontSize:'9px',
  162. textAlign:'center',
  163. fontFamily:'Helvetica',
  164. margin:'0',
  165. color:'white'
  166. })
  167. buttON.onclick = function(){
  168. const inputValue = document.getElementById('input').value
  169. const pixel = 16
  170. let em = ((inputValue*100)/pixel)/100
  171. inPut.type='text'
  172. document.getElementById('input').value = inputValue + ' px' + ' = ' + em +' em'
  173. Object.assign(inPut.style,{fontWeight:'bold'})
  174. const link = document.createElement('a')
  175. const linkText = document.createTextNode('Еще конвертация?')
  176. link.appendChild(linkText)
  177. link.href = 'index.html'
  178. div.appendChild(link)
  179. Object.assign(link.style,
  180. {
  181. fontSize:'12px',
  182. textDecoration:'underline',
  183. marginTop:'15px',
  184. color:'#273648',
  185. fontWeight:'bold',
  186. cursor:'pointer'
  187. })
  188. this.onclick=null
  189. }
  190. // Calc Live ===========================================================================
  191. const div = document.createElement('div')
  192. document.body.append(div)
  193. Object.assign(div.style,
  194. {
  195. width:'500px',
  196. height:'175px',
  197. backgroundColor:'#e1ebf1',
  198. display:'flex',
  199. justifyContent:'center',
  200. flexDirection: 'column',
  201. alignItems:'center',
  202. })
  203. const h1 = document.createElement('h1')
  204. div.appendChild(h1)
  205. h1.innerText= 'КОНВЕРТИРОВАНИЕ ЗНАЧЕНИЙ ИЗ PX В EM'
  206. Object.assign(h1.style,
  207. {
  208. fontSize:'17px',
  209. textAlign:'center',
  210. fontFamily:'Helvetica',
  211. color:'#273648',
  212. margin:'0',
  213. })
  214. const inPut = document.createElement('input')
  215. inPut.id='input'
  216. inPut.type='number'
  217. inPut.oninput = liveResult
  218. inPut.placeholder='Введите значение в PX'
  219. div.appendChild(inPut)
  220. Object.assign(inPut.style,
  221. {
  222. width:'250px',
  223. height:'25px',
  224. border:'1px solid',
  225. borderColor:'white',
  226. marginTop:'15px',
  227. textAlign:'center',
  228. color:'#273648',
  229. })
  230. const inPutValues = document.createElement('input')
  231. inPutValues.id='inputValues'
  232. inPutValues.type='text'
  233. div.appendChild(inPutValues)
  234. Object.assign(inPutValues.style,
  235. {
  236. width:'250px',
  237. height:'25px',
  238. border:'1px solid',
  239. borderColor:'white',
  240. marginTop:'15px',
  241. textAlign:'center',
  242. fontWeight:'bold',
  243. color:'#273648',
  244. fontSize:'20px'
  245. })
  246. function liveResult(){
  247. const inputValue = document.getElementById('input').value
  248. const pixel = 16
  249. let em = ((inputValue*100)/pixel)/100
  250. document.getElementById('inputValues').value = em + ' em'
  251. }