@@ -4,6 +4,7 @@ const menuHamIcon = document.querySelector('.menu');
44const menuCarritoIcon = document . querySelector ( '.navbar-shopping-cart' ) ;
55const mobileMenu = document . querySelector ( '.mobile-menu' ) ;
66const aside = document . querySelector ( '.product-detail' ) ;
7+ const cardsContainer = document . querySelector ( '.cards-container' ) ;
78
89
910menuEmail . addEventListener ( 'click' , toggleDesktopMenu ) ;
@@ -13,7 +14,6 @@ menuCarritoIcon.addEventListener('click', toggleCarritoAside);
1314function toggleDesktopMenu ( ) {
1415 const isAsideClosed = aside . classList . contains ( 'inactive' ) ;
1516
16-
1717 if ( ! isAsideClosed ) {
1818 //si el mobile menu esta open, hay que cerrarlo
1919 aside . classList . add ( 'inactive' ) ;
@@ -25,7 +25,6 @@ function toggleMobileMenu() {
2525
2626 const isAsideClosed = aside . classList . contains ( 'inactive' ) ;
2727
28-
2928 if ( ! isAsideClosed ) {
3029 //si el mobile menu esta open, hay que cerrarlo
3130 aside . classList . add ( 'inactive' ) ;
@@ -49,4 +48,79 @@ function toggleCarritoAside() {
4948 }
5049
5150 aside . classList . toggle ( 'inactive' ) ;
52- }
51+ }
52+
53+ const productList = [ ] ;
54+
55+ productList . push ( {
56+ name : 'Bike' ,
57+ price : 120 ,
58+ image : 'https://images.pexels.com/photos/276517/pexels-photo-276517.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940'
59+ } ) ;
60+ productList . push ( {
61+ name : 'Pantalla' ,
62+ price : 220 ,
63+ image : 'https://images.pexels.com/photos/276517/pexels-photo-276517.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940'
64+ } ) ;
65+ productList . push ( {
66+ name : 'Compu' ,
67+ price : 620 ,
68+ image : 'https://images.pexels.com/photos/276517/pexels-photo-276517.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940'
69+ } ) ;
70+
71+ /*
72+ <div class="product-card">
73+ <img src="https://images.pexels.com/photos/276517/pexels-photo-276517.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940"
74+ alt="">
75+ <div class="product-info">
76+ <div>
77+ <p>$120,00</p>
78+ <p>Bike</p>
79+ </div>
80+ <figure>
81+ <img src="./icons/bt_add_to_cart.svg" alt="">
82+ </figure>
83+ </div>
84+ </div>
85+ */
86+
87+ function renderProducts ( arr ) {
88+ for ( product of arr ) {
89+ const productCard = document . createElement ( 'div' ) ;
90+ productCard . classList . add ( 'product-card' ) ;
91+
92+ //product = {name,price,image} -> product.image
93+ const productImg = document . createElement ( 'img' ) ;
94+ productImg . setAttribute ( 'src' , product . image )
95+
96+ const productInfo = document . createElement ( 'div' ) ;
97+ productInfo . classList . add ( 'product-info' ) ;
98+
99+ const productInfoDiv = document . createElement ( 'div' ) ;
100+
101+ const productPrice = document . createElement ( 'p' ) ;
102+ productPrice . innerText = '$' + product . price
103+
104+ const productName = document . createElement ( 'p' ) ;
105+ productName . innerText = product . name
106+
107+ productInfoDiv . appendChild ( productPrice ) ;
108+ productInfoDiv . appendChild ( productName ) ;
109+
110+ const productInfoFigure = document . createElement ( 'figure' ) ;
111+ const productImgCart = document . createElement ( 'img' ) ;
112+ productImgCart . setAttribute ( 'src' , './icons/bt_add_to_cart.svg' )
113+
114+ productInfoFigure . appendChild ( productImgCart ) ;
115+
116+ productInfo . appendChild ( productInfoDiv ) ;
117+ productInfo . appendChild ( productInfoFigure ) ;
118+
119+ productCard . appendChild ( productImg ) ;
120+ productCard . appendChild ( productInfo ) ;
121+
122+ cardsContainer . appendChild ( productCard ) ;
123+ }
124+ }
125+
126+ renderProducts ( productList ) ;
0 commit comments