HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
Any URLs added here will be added as <link>
s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
Any URL's added here will be added as <script>
s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
Search for and use JavaScript packages from npm here. By selecting a package, an import
statement will be added to the top of the JavaScript editor for this package.
Using packages here is powered by esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<section class="cards">
<div class="container">
<div class="contenedorCards"></div>
</div>
</section>
<!--
- Para una mejor experiencia miralo en FullPageView.
- El objetivo principal es mostrar el zoom en la imagen de la modal de preview, para ello da click en el boton de la "Vista Rapida" y luego al boton de "Ampliar imagen".
-->
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;600;900&display=swap');
$negro: #121618;
$blanco: #fff;
$gris: #eee;
$primario: #47d3e6;
$secundario: #232f3d;
@mixin flex ($dir: row, $wrap: wrap, $ai: center, $jc: center, $ac: center){
display: flex;
flex-direction: $dir;
flex-wrap: $wrap;
align-items: $ai;
justify-content: $jc;
align-content: $ac;
}
@mixin imagen ($url: '', $size: cover, $posicion: center, $repeat: no-repeat) {
@if $url != '' {
background-image: url($url);
}
background-size: $size;
background-position: $posicion;
background-repeat: $repeat;
}
@mixin ellipsisParrafo($lineas: 3){
-webkit-line-clamp: $lineas;
-webkit-box-orient: vertical;
overflow: hidden;
text-overflow: ellipsis;
display: -webkit-box;
}
// Media Queries
@mixin desktop {
@media only screen and (max-width: 1024px){ @content; }
}
@mixin tablet {
@media only screen and (max-width: 768px){ @content; }
}
@mixin mobile {
@media only screen and (max-width: 480px){ @content; }
}
@mixin responsivo($medida) {
@media only screen and (max-width: $medida){ @content; }
}
:root{
--currencyPrefix: "$";
}
body{
overflow-x: hidden;
color: #666;
padding: 0;
margin: 0 auto;
*{
font-family: 'Inter', sans-serif;
@include mobile{
cursor: default !important;
}
}
p{
margin: 0;
}
a {
color: #666;
text-decoration: none;
}
ul, li{
padding: 0;
margin: 0;
list-style-type: none;
}
}
//Keyframes para animaciones
@keyframes anim_toCartCantidad {
0%, 100% {
transform: translateY(0);
opacity: 1;
}
50% {
transform: translateY(-50%);
opacity: 0;
}
51% {
transform: translateY(50%);
opacity: 0;
}
}
@keyframes anim_favsHeart {
0% {transform: scale(1);}
50% {transform: scale(1.2);}
}
//Generales
.disabled{
opacity: .5;
cursor: not-allowed !important;
* {
pointer-events: none !important;
}
}
.component_toCartCantidad{
@include flex;
border-radius: 100px;
border: 1px solid $gris;
.toCartBoton{
@include flex;
width: 40px;
height: 40px;
color: $negro;
border-radius: 50%;
background-color: $gris;
position: relative;
cursor: pointer;
&.menos{
&:after{
display: none;
}
}
&:before, &:after{
content: "";
position: absolute;
width: calc(100% - 30px);
height: 2px;
background-color: currentColor;
}
&:after{
transform: rotate(90deg);
}
}
.toCartCantidad{
min-width: 50px;
font-size: 20px;
font-weight: 900;
user-select: none;
&.animacion{
animation: anim_toCartCantidad .2s;
&-reverse{
animation: anim_toCartCantidad reverse .2s;
}
}
}
}
.boton{
display: block;
padding: 10px 20px;
color: $blanco;
font-size: 12px;
text-align: center;
letter-spacing: 1px;
text-transform: uppercase;
border-radius: 50px;
background-color: $secundario;
transition: ease all .3s;
cursor: pointer;
&:hover{
transform: translateY(-5px);
box-shadow: 0 10px 10px 0 rgba($negro,.1);
}
}
.botonTextoIcono{
@include flex;
color: $blanco;
font-size: 12px;
text-align: center;
letter-spacing: 1px;
text-transform: uppercase;
border-radius: 50px;
background-color: $secundario;
cursor: pointer;
overflow: hidden;
position: relative;
&:hover{
.labelBoton{
transform: translateY(-100%);
}
.icono{
bottom: 50%;
transform: translateY(50%);
}
}
.labelBoton{
margin-bottom: 0;
padding: 10px 20px;
transition: ease all .2s;
}
.icono{
position: absolute;
bottom: 0;
color: $blanco;
width: 25px;
height: 25px;
transform: translateY(100%);
transition: ease all .2s;
svg{
path, circle{
fill: none;
stroke-width: 4;
stroke: currentColor;
stroke-miterlimit: 10;
}
}
}
}
.botonIcono{
border-radius: 50px;
color: $secundario;
border: 1px solid $secundario;
cursor: pointer;
transition: ease all .3s;
.icono{
width: 20px;
height: 20px;
padding: 10px;
svg{
path, circle{
fill: transparent;
stroke-width: 2;
stroke: currentColor;
stroke-miterlimit: 10;
transition: ease all .3s;
}
}
}
}
.cards{
@include flex;
width: 100%;
min-height: 100vh;
max-width: 1600px;
margin: 0 auto;
.container{
width: 90%;
margin: 0 auto;
padding: 20px 0;
.contenedorCards{
@include flex;
}
}
}
.card{
width: 25%;
min-width: 300px;
.innerProd{
height: calc(100% - 20px);
margin: 10px;
border-radius: 5px;
display: block;
border: 1px solid $gris;
background-color: $blanco;
overflow: hidden;
user-select: none;
transition: ease all .3s;
&:hover{
box-shadow: 0 5px 10px 0 rgba($negro,.2);
}
.imgWrapper{
@include flex;
width: 100%;
height: 200px;
box-sizing: border-box;
background-color: $gris;
position: relative;
&:hover{
.imgProd{
transform: scale(.8);
}
.detalleRapido{
width: 100%;
height: 100%;
opacity: 1;
}
}
.detalleRapido{
@include flex(column);
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
margin: auto;
width: 90%;
height: 90%;
padding: 20px;
opacity: 0;
color: $blanco;
font-size: 12px;
letter-spacing: 1px;
text-transform: uppercase;
background-color: rgba($negro,.9);
box-sizing: border-box;
overflow: hidden;
cursor: pointer;
z-index: 1;
transition: ease all .3s;
.icono{
width: 35px;
height: 35px;
margin-bottom: 5px;
svg{
path, circle{
fill: none;
stroke: currentColor;
}
}
}
}
.imgProd{
@include imagen('', contain);
width: calc(100% - 20px);
height: calc(100% - 20px);
margin: 10px;
transition: ease all .3s;
}
}
.info{
padding: 20px 10px;
text-align: center;
display: block;
height: 180px;
box-sizing: border-box;
.prodName{
@include ellipsisParrafo(2);
margin: 0 auto;
margin-bottom: 10px;
color: $negro;
font-weight: 600;
}
.prodDesc{
@include ellipsisParrafo;
margin: 0 auto;
max-width: 80%;
font-size: 12px;
margin-bottom: 10px;
}
.precios{
@include flex($wrap: nowrap, $jc: space-between);
.precio{
font-size: 25px;
font-weight: 600;
color: $secundario;
&:before{
content: var(--currencyPrefix);
font-size: 18px;
text-transform: uppercase;
}
}
.stock{
@include flex($wrap: nowrap);
font-size: 14px;
font-weight: 600;
text-align: right;
&.out{
&:before{
background-color: red;
}
}
&:before{
content: "";
width: 10px;
height: 10px;
min-width: 10px;
margin-right: 5px;
border-radius: 50%;
background-color: green;
}
}
.precioOriginal{
color: red;
font-weight: 600;
text-align: right;
text-decoration: line-through;
&:before{
content: var(--currencyPrefix);
font-size: 14px;
text-transform: uppercase;
}
}
}
}
.actions{
@include flex;
padding: 20px 10px;
.boton{
margin-bottom: 30px;
padding: 10px 20px;
color: $blanco;
font-size: 14px;
font-weight: 600;
text-align: center;
letter-spacing: 1px;
text-transform: uppercase;
border-radius: 50px;
background-color: $secundario;
cursor: pointer;
transition: cubic-bezier(0.68, -0.55, 0.27, 1.55) all .5s;
&:hover{
transform: translateY(-5px);
box-shadow: 0 5px 10px 0 rgba($negro,.5);
}
}
.row-buttons{
@include flex(row, nowrap, center, space-between);
width: 100%;
.checkBox{
@include flex;
position: relative;
cursor: pointer;
input{
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
margin: 0;
opacity: 0;
z-index: 1;
cursor: pointer;
&:checked{
~.icon{
&:after{
width: 80%;
height: 80%;
}
}
}
}
.icon{
@include flex;
width: 20px;
height: 20px;
margin-right: 5px;
border-radius: 50%;
border: 1px solid $secundario;
position: relative;
&:after{
@include flex;
content: "✓";
position: absolute;
width: 0;
height: 0;
color: $blanco;
font-size: 10px;
border-radius: 50%;
background-color: $primario;
transition: cubic-bezier(0.68, -0.55, 0.27, 1.55) all .3s;
}
}
.checkBoxLabel{
font-size: 12px;
font-weight: 600;
letter-spacing: 1px;
text-transform: uppercase;
}
}
.favoritos{
@include flex;
font-size: 12px;
font-weight: 600;
letter-spacing: 1px;
text-transform: uppercase;
cursor: pointer;
&:after{
content: "A favoritos";
}
&.esFav{
&:after{
content: "En favoritos";
}
.icono{
animation: anim_favsHeart .2s linear;
svg{
path{
fill: red;
}
}
}
}
.icono{
width: 20px;
height: 20px;
margin-right: 5px;
color: red;
svg{
overflow: hidden;
path{
fill: transparent;
stroke: currentColor;
stroke-width: 2;
stroke-miterlimit: 10;
transition: ease all .3s;
}
}
}
}
}
}
}
}
.infoRapidaModal{
@include flex;
display: none;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba($negro,.8);
z-index: 1000;
.closeModal{
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
cursor: pointer;
}
.modalContainer{
width: 90%;
margin: 0 auto;
max-width: 1000px;
background-color: $blanco;
position: relative;
.topContent{
@include flex($ai: stretch);
width: 100%;
.imagenContainer{
@include flex;
width: 50%;
min-height: 500px;
background-color: $gris;
box-sizing: border-box;
position: relative;
.zoomWatch{
position: absolute;
top: 20px;
left: 20px;
width: 20px;
height: 20px;
padding: 15px;
border-radius: 50%;
color: $negro;
background-color: $blanco;
box-shadow: 0 0 10px 0 rgba($negro,.1);
z-index: 1;
cursor: pointer;
svg{
path{
fill: none;
stroke-width: 2;
stroke: currentColor;
stroke-miterlimit: 10;
}
}
}
.wrapperImg{
width: 100%;
height: 100%;
padding: 50px;
box-sizing: border-box;
position: relative;
overflow: hidden;
.imagen{
@include imagen($size: contain);
width: 100%;
height: 100%;
}
.zoom_lupa{
position: absolute;
top: 0;
left: 0;
opacity: .5;
background-color: $blanco;
border: 1px solid rgba($negro,.2);
box-sizing: border-box;
cursor: move;
}
}
.zoomImg{
display: none;
position: absolute;
top: 0;
left: 100%;
width: 100%;
height: 100%;
background-color: $blanco;
overflow: hidden;
z-index: 1;
.zoom{
@include imagen($size: contain);
width: 100%;
height: 100%;
}
}
}
.texto{
@include flex;
width: 50%;
.wrapper{
@include flex(column, nowrap, center, flex-start);
padding: 50px 20px;
text-align: center;
max-height: 90vh;
overflow: auto;
box-sizing: border-box;
.actions{
@include flex;
margin: 30px auto;
.botonTextoIcono{
margin: 0 10px 0 20px;
}
.botonIcono{
&.esFav{
color: red;
border-color: currentColor;
background-color: currentColor;
&:hover{
path, circle{
fill: $blanco;
}
}
path, circle{
fill: $blanco;
}
}
&:hover{
path, circle{
fill: red;
stroke: red;
}
}
}
}
p{
font-size: 14px;
}
.bold{
font-weight: 600;
}
.nombre{
font-size: 25px;
font-weight: 900;
}
.precios{
@include flex;
margin: 10px auto;
}
.precio{
@include flex($wrap: nowrap);
font-size: 30px;
font-weight: 900;
color: $secundario;
margin-bottom: 0;
&:before{
font-size: 20px;
content: var(--currencyPrefix);
}
}
.precioOferta{
@extend .precio;
color: red;
font-size: 20px;
margin-left: 10px;
text-decoration: line-through;
}
.stock{
@include flex($wrap: nowrap);
margin-bottom: 5px;
&.out{
&:before{
background-color: red;
}
}
&:before{
content: "";
width: 10px;
height: 10px;
min-width: 10px;
margin-right: 5px;
border-radius: 50%;
background-color: green;
}
}
.boton{
margin-top: 30px;
}
}
}
}
}
@include tablet{
.modalContainer{
.topContent{
.imagenContainer, .texto{
width: 100%;
}
.imagenContainer{
min-height: 250px;
.zoomWatch{
display: none;
}
.wrapperImg{
padding: 10px;
}
.zoomImg{
top: 100%;
left: 0;
}
}
.texto{
.wrapper{
max-height: calc(90vh - 250px);
padding: 20px;
}
}
}
}
}
@include mobile{
.modalContainer{
.topContent{
.imagenContainer{
min-height: 200px;
}
.texto{
.wrapper{
max-height: calc(90vh - 200px);
.nombre{
font-size: 20px;
}
.actions{
flex-direction: column;
width: 100%;
margin: 20px auto;
.botonTextoIcono{
margin: 20px auto 0 auto;
}
.botonIcono{
position: absolute;
top: 10px;
right: 10px;
}
}
}
}
}
}
}
}
$(function(){
//Datos de prueba
const datosCards = [
{
id: 1,
imagen: 'https://firebasestorage.googleapis.com/v0/b/fotos-3cba1.appspot.com/o/producto1.png?alt=media&token=915bea59-e6c2-4474-bc72-abc1c47ef1c7',
nombre: 'Tarjeta de video Gigabyte GTX 1650 D6 OC 4GB GDDR6',
descripcionCorta: 'Graphics Processing GeForce® GTX 1650 Core Clock',
descripcionLarga: 'Alimentado por la arquitectura GeForce GTX 1650 NVIDIA Turing y GeForce Experience Integrado con 4 GB GDDR6 128 bit interfaz de memoria WINDFORCE 2X Sistema de enfriamiento con ventiladores giratorios alternativos de 80 mm ventiladores de hoja únicos Core Clock: 1710 MHz',
precio: 5000,
precioOferta: 4399,
existencia: true,
codigoProducto: 'H410M-APRO'
},
{
id: 2,
imagen: 'https://firebasestorage.googleapis.com/v0/b/fotos-3cba1.appspot.com/o/producto2.png?alt=media&token=0d966e78-66be-43bd-a21b-98007831b9f6',
nombre: 'Teclado mecanico para gaming Hyperex Alloy origins RGB',
descripcionCorta: 'HyperX Alloy Origins mecánico Tenkeyless para Gaming RGB',
descripcionLarga: 'Es un teclado compacto y robusto que cuenta con interruptores mecánicos diseñados para brindarle a los gamers la mejor combinación de estilo, rendimiento y confiabilidad. Estos interruptores mecánicos tienen LEDs expuestos para lograr una iluminación impresionante con una fuerza de accionamiento y una distancia de trayectoria equilibrada para obtener un alto nivel de respuesta y exactitud. Alloy Origins está construido con un cuerpo de aluminio sólido que lo mantiene rígido y estable cuando la acción lo requiera, y te permitirá elegir entre tres niveles diferentes de inclinación. Su diseño elegante y compacto deja más espacio para el movimiento del mouse y también cuenta con un cable USB tipo C extraíble para una mejor portabilidad.',
precio: 1280,
existencia: true,
codigoProducto: 'AS13C-RAWQ'
},
{
id: 3,
imagen: 'https://firebasestorage.googleapis.com/v0/b/fotos-3cba1.appspot.com/o/producto3.png?alt=media&token=453593c9-9630-4de0-8ba4-a3a780a1cc6a',
nombre: 'Headset para gaming Hyperx Cloud Stringer S 7.1 CH con Mic USB',
descripcionCorta: 'Conexión inalámbrica de 2,4Ghz y almohadillas resistentes',
descripcionLarga: 'Los audífonos HyperX Cloud Stinger™ son audífonos con licencia oficial PS4 y son ideales para gamers que buscan confort, calidad de sonido superior y una mayor comodidad. Son livianos y cuentan con memory foam original de HyperX, lo que permite brindar un nivel de confort legendario durante sesiones maratónicas de juego. Sus orejeras giratorias de 90 grados pueden descansar cómodamente alrededor de tu cuello durante los descansos.',
precio: 1348,
precioOferta: 765,
existencia: false,
codigoProducto: '43REQ-TYI1'
},
{
id: 4,
imagen: 'https://firebasestorage.googleapis.com/v0/b/fotos-3cba1.appspot.com/o/producto4.png?alt=media&token=6c0ae77e-e48a-4b49-babc-0fc1023aa66a',
nombre: 'Tarjeta madre Gigabyte B550M-DS3H Ryzen 3000 series Matx',
descripcionCorta: 'Soporta AMD 3rd Gen Ryzen™ y 3rd Gen Ryzen™ con Radeon™ GPU',
descripcionLarga: 'Las placas base de la serie GIGABYTE UD utilizan un diseño MOSFET PWM + Low RDS(on) digital puro de 5 + 3 fases para admitir las CPU AMD Ryzen ™ de tercera generación al ofrecer una precisión increíble en la entrega de energía a los componentes más sensibles a la energía y a la energía de la placa base.Además de ofrecer un rendimiento mejorado del sistema y la máxima escalabilidad del hardware.',
precio: 2699,
existencia: false,
codigoProducto: 'TYUT7-FNTG'
}
];
//Pintamos las terjetas cuando carga el documento
pintarCards($('.cards .contenedorCards'), datosCards);
//Lanzamos la modal de detalles rapidos
$('.card .detalleRapido').click(function(){
let id = $(this).data('id');
let info = datosCards.find(prod => prod.id == id);
detallesRapidos(info);
})
//Sumar o restar un producto para enviar al carrito
$(document).on('click', '.component_toCartCantidad .toCartBoton', function(){
const boton = $(this);
toCartCantidad(boton, boton.hasClass('mas') ? 'suma' : boton.hasClass('menos') ? 'resta' : null);
});
//Enviar producto a favoritos
$(document).on('click', '.aFavs', function(){
$(this).toggleClass('esFav');
})
//Cargamos el zoomIn a la imagen para verla mejor xD
$(document).on('click', '.infoRapidaModal .zoomWatch', function(){
var areaImagen = $(this).parent();
zoomImg(areaImagen);
})
//Salir de la modal dando clic en la tecla de escape
$(document).keydown(function(e){
if ($('.infoRapidaModal').length && e.keyCode === 27) {
$('.infoRapidaModal').fadeOut(function(){
$(this).remove();
})
}
})
//Fx que mapea los datos para pintarlos en el contenedor
function pintarCards(contenedorCards, datos){
datos.map(card => {
let clases = 'card';
if (!card.precioOferta) clases += ' oferta';
if (!card.existencia) clases += ' out';
contenedorCards.append(`
<div class="${clases}">
<div class="innerProd">
<div class="imgWrapper">
<div class="detalleRapido" data-id="${card.id}">
<div class="icono">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64">
<path d="M39.049 39.049L56 56"></path>
<circle cx="27" cy="27" r="17"></circle>
</svg>
</div>
<p>Vista rapida</p>
</div>
<div class="imgProd" style="background-image: url(${card.imagen});"></div>
</div>
<a class="info" href="#">
<p class="prodName">${card.nombre}</p>
<p class="prodDesc">${card.descripcionCorta}</p>
<div class="precios">
<p class="precio">${card.precioOferta || card.precio}</p>
<div>
${card.precioOferta ? `<p class="precioOriginal">${card.precio}</p>`:''}
<p class="stock ${!card.existencia ? 'out' :''}">${card.existencia ? 'En existencia' : 'Fuera de stock'}</p>
</div>
</div>
</a>
<div class="actions">
<div class="boton alCarrito">Agregar al carrito</div>
<div class="row-buttons">
<div class="checkBox comparar">
<input type="checkbox">
<div class="icon"></div>
<p class="checkBoxLabel">Comparar</p>
</div>
<div class="aFavs favoritos">
<div class="icono">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64">
<path d="M47 5c-6.5 0-12.9 4.2-15 10-2.1-5.8-8.5-10-15-10A15 15 0 0 0 2 20c0 13 11 26 30 39 19-13 30-26 30-39A15 15 0 0 0 47 5z"></path>
</svg>
</div>
</div>
</div>
</div>
</div>
</div>`
);
})
}
//Fx que dibuja y lanza la modal de detalles rapidos
function detallesRapidos(datos){
const { codigoProducto, descripcionLarga, existencia, imagen, nombre, precio, precioOferta } = datos;
if (!$('.infoRapidaModal').length) {
$('body').append(`
<div class="infoRapidaModal">
<div class="closeModal"></div>
<div class="modalContainer">
<div class="topContent">
<div class="imagenContainer zoom_section">
<div class="zoom_launcher zoomWatch" title="Ampliar imagen">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64">
<path d="M2.002 40h22v22h-22z"></path>
<path d="M2 28V2h60v60H36"></path>
<path d="M30 34l22-22m-16 0h16v16"></path>
</svg>
</div>
<div class="zoom_imgOrigin wrapperImg">
<div class="zoom_imgSource imagen" style="background-image: url(${imagen});"></div>
</div>
</div>
<div class="texto">
<div class="wrapper">
<p class="nombre">${nombre}</p>
<div class="precios">
<p class="precio">${precioOferta || precio}</p>
${precioOferta ? `<p class="precioOferta">${precio}</p>` :''}
</div>
<p class="stock ${existencia ?'':'out'} bold">${existencia ? 'Disponible en tienda y listo para enviar' : 'Fuera de stock'}</p>
<p class="codigo"><span class="bold">Código Producto: </span>${codigoProducto}</p>
<div class="actions">
<div class="component_toCartCantidad ${!existencia ? 'disabled':''}">
<div class="toCartBoton menos disabled"></div>
<div class="toCartCantidad">1</div>
<div class="toCartBoton mas"></div>
</div>
<div class="botonTextoIcono ${!existencia ? 'disabled' : ''}">
<label class="labelBoton">Agregar al carrito</label>
<div class="icono">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64">
<path d="M2 6h10l10 40h32l8-24H16"></path>
<circle cx="23" cy="54" r="4"></circle>
<circle cx="49" cy="54" r="4"></circle>
</svg>
</div>
</div>
<div class="aFavs botonIcono">
<div class="icono">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64">
<path d="M47 5c-6.5 0-12.9 4.2-15 10-2.1-5.8-8.5-10-15-10A15 15 0 0 0 2 20c0 13 11 26 30 39 19-13 30-26 30-39A15 15 0 0 0 47 5z"></path>
</svg>
</div>
</div>
</div>
<p class="descripcion">${descripcionLarga}</p>
<a class="boton" href="#">Ver detalles completos</a>
</div>
</div>
</div>
</div>
</div>
`);
}
$('.infoRapidaModal').fadeIn().css('display', 'flex');
$('.infoRapidaModal .closeModal').click(function(){
$(this).parent().fadeOut(function(){
$(this).remove();
})
})
}
//Fx que actualiza la cantidad de articulos que queremos enviar al carrito
function toCartCantidad(boton, operacion){
const container = boton.parents('.component_toCartCantidad');
const numero = container.find('.toCartCantidad');
let tipoAnim = 'normal';
if (operacion == 'resta') {
if (parseInt(numero.text()) == 1) return false;
if (parseInt(numero.text() - 1) == 1) {
boton.addClass('disabled');
}
tipoAnim = 'reverse';
numero.text(parseInt(numero.text()) - 1);
} else if (operacion == 'suma') {
boton.siblings('.toCartBoton.disabled').removeClass('disabled');
numero.text(parseInt(numero.text()) + 1);
} else {
console.log('El tipo de operacion (suma / resta) es obligatorio');
return false;
}
numero.addClass(tipoAnim == 'reverse' ? 'animacion-reverse' : 'animacion');
numero.one('animationend', function () {
numero.removeClass(tipoAnim == 'reverse' ? 'animacion-reverse' : 'animacion');
});
}
//Fx que maneja el zoomIn en la imagen
function zoomImg(zoomArea, escala = 3){
if ($(window).width() > 768) {
zoomArea.find('.zoom_launcher').fadeOut('fast');
const imagen = zoomArea.find('.zoom_imgOrigin');
const urlImagen = zoomArea.find('.zoom_imgSource')[0].style.backgroundImage;
const dimensiones = {
imagen: {width: imagen.outerWidth(), height: imagen.outerHeight()},
lupa: {width: imagen.outerWidth() / escala, height: imagen.outerHeight() / escala}
};
const estiloInicial = {
backgroundImage: urlImagen,
backgroundSize: parseInt(imagen.css('padding')) ? `calc(100% - (${(parseInt(imagen.css('padding')) / 2) * escala}px))` : 'contain',
transform: `scale(${escala}) translateX(${dimensiones.imagen.width / escala}px) translateY(${dimensiones.imagen.height / escala}px)`
};
imagen.append(`<div class="zoom_lupa"></div>`);
zoomArea.append(`<div class="zoom_imgAlt zoomImg"><div class="zoom"></div></div>`);
const scaleArea = zoomArea.children('.zoom_imgAlt');
const zoom = scaleArea.children('.zoom');
const lupa = imagen.children('.zoom_lupa');
scaleArea.fadeIn();
zoom.css(estiloInicial);
lupa.css(dimensiones.lupa);
imagen.mousemove(function(e){
let movimientoLupa = {x: e.pageX, y: e.pageY};
let centroImagen = {
x: (imagen.offset().left + (dimensiones.imagen.width / 2)),
y: (imagen.offset().top + (dimensiones.imagen.height / 2))
}
let posicionLupa = {
x: centroImagen.x - movimientoLupa.x,
y: centroImagen.y - movimientoLupa.y
}
let transformLupa = {
x: (movimientoLupa.x - (dimensiones.lupa.width / 2)) - imagen.offset().left,
y: (movimientoLupa.y - (dimensiones.lupa.height / 2)) - imagen.offset().top
}
var transformZoom = (`scale(${escala}) translateX(${posicionLupa.x}px) translateY(${posicionLupa.y}px)`);
zoom.css('transform', transformZoom);
lupa.css('transform', `translateX(${transformLupa.x}px) translateY(${transformLupa.y}px)`);
});
imagen.mouseout(function(){
lupa.remove();
zoomArea.find('.zoom_launcher').fadeIn('fast');
scaleArea.fadeOut('fast', function(){
scaleArea.remove();
})
})
} else {
console.warn('Solo disponible para pc');
}
}
})
Also see: Tab Triggers