diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 00000000..4a1aa310 Binary files /dev/null and b/.DS_Store differ diff --git a/README.md b/README.md index e70983a3..e69de29b 100644 --- a/README.md +++ b/README.md @@ -1,2 +0,0 @@ -# javascript-amazon -레벨3 diff --git a/img/logo.png b/img/logo.png new file mode 100644 index 00000000..927cc41e Binary files /dev/null and b/img/logo.png differ diff --git a/index.html b/index.html new file mode 100644 index 00000000..1a32a32a --- /dev/null +++ b/index.html @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + diff --git a/index.js b/index.js new file mode 100644 index 00000000..5755226a --- /dev/null +++ b/index.js @@ -0,0 +1,71 @@ +class Carousel { + constructor (menuData,contentData) { + this.menuData=menuData; + this.contentData=contentData; + this.makingMenuList(); + this.makingSlider(); + this.btnHandler(); + this.count = 0; + } + changeLocation (element,index) { + this.count = index; + const width = element.children[0].getBoundingClientRect().width; + element.style.transform = `translateX(${-this.count*width}px)`; + } + scaleMenu (element,index) { + this.count = index; + Array.from(element.parentNode.children).forEach((element)=>element.style.transform=`scale(0.99)`) + element.parentNode.children[this.count].style.transform = 'scale(1.1)'; + } + btnHandler () { + const left =document.querySelector('div.carousel__button--prev'); + const right =document.querySelector('div.carousel__button--next'); + [left,right].forEach((btn,index)=>{ + btn.addEventListener('click',()=>{ + index === 0 ? this.count-- : this.count++; + if (this.count >3) this.count =0; + if (this.count<0) this.count =3; + const el = document.querySelector('.carousel__container'); + this.changeLocation(el,this.count); + this.scaleMenu(document.querySelector('.menu__list>li'),this.count); + }); + }) + } + makingMenuList () { + const menuConatiner=document.querySelector('.menu__list') + this.menuData.forEach((data)=>{ + menuConatiner.innerHTML +=` +
  • ${data}
  • ` + }) + Array.from(menuConatiner.children).forEach((li,index)=>{ + li.addEventListener('click',()=>{ + this.scaleMenu(li,index); + this.changeLocation(document.querySelector('.carousel__container'),index); + }) + }) + } + makingSlider () { + const carouselContainer = document.querySelector('.carousel__container'); + carouselContainer.innerHTML=this.contentData.map((data,index)=>` + `).join(''); + } +} + +window.addEventListener('DOMContentLoaded',()=>{ + fetch('./localData.json') + .then((data)=>data.json()) + .then((data)=>{ + const {menuData,contentData}=data; + const carousel=new Carousel(menuData,contentData); + }) +}); \ No newline at end of file diff --git a/localData.json b/localData.json new file mode 100644 index 00000000..7d0ef075 --- /dev/null +++ b/localData.json @@ -0,0 +1,35 @@ +{ + "menuData" : [ + "Fast, Free Delivery", + "Exclusive deals and offers", + "Prime Originals, movies and TV shows", + "Over 2 million song ad free" + ], + "contentData" : [{ + "id" : "1", + "imgUrl" : "https://placedog.net/200/250?id=8", + "title" :"Enjoy exclusive savings and rewards", + "desc" : ["Fast, Free Delivery", + "Exclusive deals and offers","Prime Originals, movies and TV shows","Over 2 million song ad free"] + },{ + "id" : "2", + "imgUrl" : "https://placedog.net/200/250?id=12", + "title" :"Code Squad is awesome place", + "desc" : ["Code, Feel JS", + "Do you want to be Front Engeneer?","Come to us Master,Good People","Waiting For you!"] + },{ + "id" : "3", + "imgUrl" :"https://placedog.net/200/250?id=14", + "title" :"Learning With practice and enthusiastic people", + "desc" : ["React to ur Mind", + "Es6 class is good for you","We will find answer","As we've done so far"] + },{ + "id" : "4", + "imgUrl" : "https://placedog.net/200/250?id=15", + "title" :"Watching Dog makes inner-peace", + "desc" : ["It was hard Day.", + "Do you feel exhausted?","Come to Our good puppy","puppy would be with you"] + } + ] +} + \ No newline at end of file diff --git a/search.css b/search.css new file mode 100644 index 00000000..1da0e535 --- /dev/null +++ b/search.css @@ -0,0 +1,70 @@ +* { + margin: 0; + padding: 0; + box-sizing: content-box; +} +body { + font: 16px Arial; +} +header { + padding: 15px; + display: flex; + height: 40px; + justify-content: space-between; + align-items: center; + background-color: #242F40; +} +.logo { + display: block; + width: 70px; + height: 40px; +} +.form-container { + width: 100%; + display: flex; + justify-content: center; +} +.autocomplete { + /*the container must be positioned relative:*/ + position: relative; + display: inline-block; + width: 350px; +} +input { + border: 1px solid transparent; + border-radius: 5px; + background-color: #f1f1f1; + padding: 10px; + font-size: 16px; +} +input[type=text] { + background-color: #f1f1f1; + width: 94%; +} +input[type=submit] { + background-color: DodgerBlue; + color: #fff; +} +.autocomplete-items { + position: absolute; + border: 1px solid #d4d4d4; + border-bottom: none; + border-top: none; + z-index: 99; + top: 100%; + left: 0; + right: 0; +} +.autocomplete-items div { + padding: 10px; + cursor: pointer; + background-color: #fff; + border-bottom: 1px solid #d4d4d4; +} +.autocomplete-items div:hover { + background-color: #e9e9e9; +} +.autocomplete-active { + background-color: DodgerBlue !important; + color: #ffffff; +} \ No newline at end of file diff --git a/search.html b/search.html new file mode 100644 index 00000000..94e6b756 --- /dev/null +++ b/search.html @@ -0,0 +1,26 @@ + + + + + + + + Document + + +
    +
    + +
    +
    +
    +
    + +
    + +
    +
    +
    + + + \ No newline at end of file diff --git a/search.js b/search.js new file mode 100644 index 00000000..d3a793cc --- /dev/null +++ b/search.js @@ -0,0 +1,95 @@ +class Search { + constructor (data,{autoComplete,input}) { + this.autoComplete = autoComplete; + this.data = data; + this.input = input; + this.autoCompleteItems; + this.currentTargetIndex=-1; + this.handleInputChange(); + this.handleKeyDown(); + this.closeAllList() + } + handleInputChange () { + this.input.addEventListener('input',(e)=>{ + const value = this.input.value; + if (!value) return; + const autoCompleteItemsExits = !!document.querySelector('.autocomplete-items'); + if (autoCompleteItemsExits) { + this.autoCompleteItems.parentNode.removeChild(this.autoCompleteItems); + } + this.autoCompleteItems = document.createElement('div'); + this.autoCompleteItems.classList.add('autocomplete-items') + this.autoComplete.appendChild(this.autoCompleteItems); + const addList =()=>{ + this.data.forEach((dataValue)=>{ + if (dataValue.substring(0,value.length).toUpperCase()===value.toUpperCase()) { + const contentDiv = document.createElement('div'); + contentDiv.innerHTML=`${dataValue.substring(0,value.length)}${dataValue.substring(value.length)}` + this.autoCompleteItems.appendChild(contentDiv); + contentDiv.addEventListener('click',(e)=>{ + this.input.value = e.target.querySelector('input').value; + }) + } + }) + } + setTimeout(()=>{ + addList(); + },300) + }) + } + closeAllList () { + document.addEventListener('click',(e)=>{ + e.preventDefault(); + const itemContainer=document.querySelector('.autocomplete-items'); + if (!itemContainer) return; + if (e.target!==this.input && e.target!==itemContainer ) { + itemContainer.parentNode.removeChild(itemContainer); + } + }) + } + handleKeyDown () { + this.input.addEventListener('keydown',(e)=>{ + if (e.which === 40) { + this.currentTargetIndex++; + if (!this.autoCompleteItems) return; + let checkOutOfListIndex=this.currentTargetIndex >= this.autoCompleteItems.children.length; + if (checkOutOfListIndex) this.currentTargetIndex=0; + Array.from(this.autoCompleteItems.children).forEach((item)=>{ + item.classList.remove('autocomplete-active')}); + let choosedTarget =this.autoCompleteItems.children[this.currentTargetIndex]; + choosedTarget=this.autoCompleteItems.children[this.currentTargetIndex]; + choosedTarget.classList.add('autocomplete-active'); + this.input.value = choosedTarget.querySelector('input').value + } else if (e.which === 38) { + this.currentTargetIndex--; + if (!this.autoCompleteItems) return; + let checkOutOfListIndex=this.currentTargetIndex < 0; + if (checkOutOfListIndex) this.currentTargetIndex=this.autoCompleteItems.children.length-1; + Array.from(this.autoCompleteItems.children).forEach((item)=>{ + item.classList.remove('autocomplete-active')}); + let choosedTarget =this.autoCompleteItems.children[this.currentTargetIndex]; + choosedTarget=this.autoCompleteItems.children[this.currentTargetIndex]; + choosedTarget.classList.add('autocomplete-active'); + this.input.value = choosedTarget.querySelector('input').value + } else if (e.which === 13) { + e.preventDefault(); + if (this.currentTargetIndex > -1) { + this.autoCompleteItems.children[this.currentTargetIndex].click(); + } + } + }) + } +} + +window.addEventListener('DOMContentLoaded',()=>{ + fetch('./searchData.json') + .then((data)=>data.json()) + .then((searchData)=>{ + const targetElement= { + autoComplete : document.querySelector('.autocomplete'), + input : document.querySelector('input#searchBar') + } + const search = new Search(searchData.data,targetElement); + }); +}) + diff --git a/searchData.json b/searchData.json new file mode 100644 index 00000000..73200eda --- /dev/null +++ b/searchData.json @@ -0,0 +1,3 @@ +{ + "data" :["Korea","Afghanistan","Albania","Algeria","Andorra","Angola","Anguilla","Antigua & Barbuda","Argentina","Armenia","Aruba","Australia","Austria","Azerbaijan","Bahamas","Bahrain","Bangladesh","Barbados","Belarus","Belgium","Belize","Benin","Bermuda","Bhutan","Bolivia","Bosnia & Herzegovina","Botswana","Brazil","British Virgin Islands","Brunei","Bulgaria","Burkina Faso","Burundi","Cambodia","Cameroon","Canada","Cape Verde","Cayman Islands","Central Arfrican Republic","Chad","Chile","China","Colombia","Congo","Cook Islands","Costa Rica","Cote D Ivoire","Croatia","Cuba","Curacao","Cyprus","Czech Republic","Denmark","Djibouti","Dominica","Dominican Republic","Ecuador","Egypt","El Salvador","Equatorial Guinea","Eritrea","Estonia","Ethiopia","Falkland Islands","Faroe Islands","Fiji","Finland","France","French Polynesia","French West Indies","Gabon","Gambia","Georgia","Germany","Ghana","Gibraltar","Greece","Greenland","Grenada","Guam","Guatemala","Guernsey","Guinea","Guinea Bissau","Guyana","Haiti","Honduras","Hong Kong","Hungary","Iceland","India","Indonesia","Iran","Iraq","Ireland","Isle of Man","Israel","Italy","Jamaica","Japan","Jersey","Jordan","Kazakhstan","Kenya","Kiribati","Kosovo","Kuwait","Kyrgyzstan","Laos","Latvia","Lebanon","Lesotho","Liberia","Libya","Liechtenstein","Lithuania","Luxembourg","Macau","Macedonia","Madagascar","Malawi","Malaysia","Maldives","Mali","Malta","Marshall Islands","Mauritania","Mauritius","Mexico","Micronesia","Moldova","Monaco","Mongolia","Montenegro","Montserrat","Morocco","Mozambique","Myanmar","Namibia","Nauro","Nepal","Netherlands","Netherlands Antilles","New Caledonia","New Zealand","Nicaragua","Niger","Nigeria","North Korea","Norway","Oman","Pakistan","Palau","Palestine","Panama","Papua New Guinea","Paraguay","Peru","Philippines","Poland","Portugal","Puerto Rico","Qatar","Reunion","Romania","Russia","Rwanda","Saint Pierre & Miquelon","Samoa","San Marino","Sao Tome and Principe","Saudi Arabia","Senegal","Serbia","Seychelles","Sierra Leone","Singapore","Slovakia","Slovenia","Solomon Islands","Somalia","South Africa","South Korea","South Sudan","Spain","Sri Lanka","St Kitts & Nevis","St Lucia","St Vincent","Sudan","Suriname","Swaziland","Sweden","Switzerland","Syria","Taiwan","Tajikistan","Tanzania","Thailand","Timor L'Este","Togo","Tonga","Trinidad & Tobago","Tunisia","Turkey","Turkmenistan","Turks & Caicos","Tuvalu","Uganda","Ukraine","United Arab Emirates","United Kingdom","United States of America","Uruguay","Uzbekistan","Vanuatu","Vatican City","Venezuela","Vietnam","Virgin Islands (US)","Yemen","Zambia","Zimbabwe"] +} diff --git a/style.css b/style.css new file mode 100644 index 00000000..68b88bb1 --- /dev/null +++ b/style.css @@ -0,0 +1,148 @@ +* { + box-sizing: border-box; + margin:0; + padding:0; +} +body,html { + margin: 0; + padding:0; +} + +.carousel__menu { + padding-top: 50px; + display: flex; +} +.carousel { + margin: 0 auto; + height: 270px; + width: 600px; + overflow: hidden; + position: relative; +} +.carousel__container { + position: relative; + display: flex; + margin-top: 40px; + width: 2450px; + height: 220px; + transition:transform .5s ease-in-out; + -webkit-transition:transform .5s ease-in-out; +} +.carousel__contents { + display: flex; + width: 600px; + height: 220px; + position: relative; + justify-content: center; + align-items: center; +} +.carousel__container .carousel__text { + width: 400px; + display: inline-block; +} +.carousel__container .carousel__text >ul>li { + margin: 3px 0; + font-size: 18px; +} +.carousel__img { + display: inline-block; + width: 220px; +} +.carousel__img > img { + width: 70%; + height: 70%; + border-radius: 50%; +} +.carousel__container .carousel__text { + line-height: 1.4; +} +.carousel__container .carousel__text > ul { + list-style: none; + font-weight: 500; +} +.carousel__button--prev { + width: 30px; + height: 30px; + font-size: 20px; + position: absolute; + display: flex; + justify-content: center; + align-items: center; + left: 10px; + top:50%; + transform: translateY(-50%); +} +.carousel__button--next { + width: 40px; + height: 40px; + font-size: 20px; + position: absolute; + display: flex; + justify-content: center; + align-items: center; + right: 20%; + top: 40%; + border: 1px solid black; + transform: translateY(-50%); + border-radius: 50%; + color: white; + background: gray; +} +.carousel__button--prev { + width: 40px; + height: 40px; + font-size: 20px; + position: absolute; + display: flex; + justify-content: center; + align-items: center; + left: 20%; + top: 40%; + border: 1px solid black; + transform: translateY(-50%); + border-radius: 50%; + color: white; + background: gray; +} +.menu__list { + margin:0 auto; + display: flex; + justify-content: space-between; + -webkit-transition: transform .5s; + transition:transform .5s; +} +.menu__list > li { + text-align: center; + width:24%; + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; + height: 80px; + padding:0 3px; + -webkit-transition: transform .5s; + transition:transform .5s; +} +.menu__list >li:last-child { + margin-right:0; +} +.menu__list>li>a { + text-decoration: none; + color:black +} + +.menu__list>li:first-child { + background-color: #2591C0; +} + +.menu__list>li:nth-child(2) { + background-color: #A90067; +} + +.menu__list>li:nth-child(3) { + background-color: #008577; +} + +.menu__list>li:nth-child(4 ) { + background-color:#E65D16; +} \ No newline at end of file