Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
clase 22
  • Loading branch information
jdbarrigab committed May 25, 2023
commit 7bc9e8cc5fd516c653f2a736a60d32e905d98ba3
1 change: 0 additions & 1 deletion clase13.html
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@
Checkout
</button>
</div>
</div>
</aside>
</body>
</html>
1 change: 1 addition & 0 deletions clase6.html
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
}
}
</style>
</head>
<body>
<section class="main-container">
<div class="cards-container">
Expand Down
19 changes: 19 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,25 @@
</div>
</aside>

<section class="main-container">
<div class="cards-container">

<div class="product-card">
<img src="https://images.pexels.com/photos/276517/pexels-photo-276517.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940" alt="">
<div class="product-info">
<div>
<p>$120,00</p>
<p>Bike</p>
</div>
<figure>
<img src="./icons/bt_add_to_cart.svg" alt="">
</figure>
</div>
</div>

</div>
</section>

<script src="./main.js"></script>
</body>
</html>
91 changes: 87 additions & 4 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,22 @@ const menuCarritoIcon = document.querySelector('.navbar-shopping-cart')
const menuHamIcon = document.querySelector('.menu');
const mobileMenu = document.querySelector('.mobile-menu');
const aside = document.querySelector('.product-detail');
const cardsContainer = document.querySelector('.cards-container');

menuEmail.addEventListener('click', toggleDesktopMenu);
menuHamIcon.addEventListener('click', toggleMobileMenu);
menuCarritoIcon.addEventListener('click', toggleCarritoAside);

function toggleDesktopMenu() {
const isAsideClosed = aside.classList.contains('inactive');

if (!isAsideClosed) {
aside.classList.add('inactive');
}

desktopMenu.classList.toggle('inactive') //modifica la classe 'inactive'
//El método toggle permite cada vez que se ejecute cambiar de estado la visibilidad del elemento HTML, es decir si está visible pasa a oculto y si se encuentra oculto pasa a visible.
}

function toggleMobileMenu() {
const isAsideClosed = aside.classList.contains('inactive');

Expand All @@ -25,11 +31,88 @@ function toggleMobileMenu() {
}

function toggleCarritoAside() {
const isMobileMenuClosed = mobileMenu.classList.contains('inactive');
const isMobileMenuClosed = mobileMenu.classList.contains('inactive');
const isDesktopMenuClosed = desktopMenu.classList.contains('inactive');

if (!isMobileMenuClosed) {
mobileMenu.classList.add('inactive');
}
if (!isDesktopMenuClosed) {
desktopMenu.classList.add('inactive')
}

aside.classList.toggle('inactive');
}

const productList = [];

productList.push({
name: 'Bike',
price: 120,
image: 'https://images.pexels.com/photos/276517/pexels-photo-276517.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940',
})
productList.push({
name: 'Pantalla',
price: 200,
image: 'https://images.pexels.com/photos/276517/pexels-photo-276517.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940',
})
productList.push({
name: 'PC',
price: 500,
image: 'https://images.pexels.com/photos/276517/pexels-photo-276517.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940',
})

/*
<div class="product-card">
<img src="https://images.pexels.com/photos/276517/pexels-photo-276517.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940" alt="">
<div class="product-info">
<div>
<p>$120,00</p>
<p>Bike</p>
</div>
<figure>
<img src="./icons/bt_add_to_cart.svg" alt="">
</figure>
</div>
</div>
*/

function renderProducts(arr) {
for (product of arr) {
const productCard = document.createElement('div')
productCard.classList.add('product-card')

//toma el src directamente desde product.image
const productImg = document.createElement('img');
productImg.setAttribute('src', product.image);

const productInfo = document.createElement('div');
productInfo.classList.add('product-info');

const productInfoDiv = document.createElement('div');

const productPrice= document.createElement('p');
productPrice.innerText = '$' + product.price;
const productName= document.createElement('p');
productName.innerText = product.name;

productInfoDiv.appendChild(productPrice);
productInfoDiv.appendChild(productName);

const productInfoFigure = document.createElement('figure');
const productImgCart = document.createElement('img');
productImgCart.setAttribute('src', './icons/bt_add_to_cart.svg');

aside.classList.toggle('inactive')
}
productInfoFigure.appendChild(productImgCart);

productInfo.appendChild(productInfoDiv);
productInfo.appendChild(productInfoFigure);

productCard.appendChild(productImg);
productCard.appendChild(productInfo);

cardsContainer.appendChild(productCard);
}
}

renderProducts(productList);
53 changes: 53 additions & 0 deletions styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,49 @@
height: 50px;
}

/* Product List */

.cards-container {
display: grid;
grid-template-columns: repeat(auto-fill, 240px);
gap: 26px;
place-content: center;
margin-top: 20px;
}
.product-card {
width: 240px;
}
.product-card img {
width: 240px;
height: 240px;
border-radius: 20px;
object-fit: cover;
}
.product-info {
display: flex;
justify-content: space-between;
align-items: center;
margin-top: 12px;
}
.product-info figure {
margin: 0;
}
.product-info figure img {
width: 35px;
height: 35px;
}
.product-info div p:nth-child(1) {
font-weight: bold;
font-size: var(--md);
margin-top: 0;
margin-bottom: 4px;
}
.product-info div p:nth-child(2) {
font-size: var(--sm);
margin-top: 0;
margin-bottom: 0;
color: var(--very-light-pink);
}
@media (max-width: 640px) {
.menu {
display: block;
Expand All @@ -250,6 +293,16 @@
.product-detail {
width: 100%;
}
.cards-container {
grid-template-columns: repeat(auto-fill, 140px);
}
.product-card {
width: 140px;
}
.product-card img {
width: 140px;
height: 140px;
}
}

@media (min-width: 641px) {
Expand Down