I am trying to create a multiple images per slide slider that show three images per slid, when click the right arrow a 3 new images should be shown, and when the left one clicked the previous 3 images returns back to be shown.
I can not manage to make that work so this is my code:
Slider Component (parent)
class Slider extends Component {
state = {
left: 0
}
moveToRight = () =>{
this.setState(prevState => ({
left: prevState.left + 500
}))
console.log(this.state.left)
}
moveToLeft = () => {
this.setState(prevState => ({
left: prevState.left - 500
}))
}
render() {
return (
<div className="slider container">
<div className="slider__arrow slider__arrow--left" onClick={this.moveToLeft}>
<i class="fa fa-angle-left fa-2x" aria-hidden="true"></i>
</div>
<Slider_content categories={this.state.categories} style={{marginLeft: `${this.state.left}px`}}/>
<div className="slider__arrow slider__arrow--right" onClick={this.moveToRight}>
<i class="fa fa-angle-right fa-2x" aria-hidden="true"></i>
</div>
</div>
);
}
}
export default Slider;
Slider_content Component:
import React, {Component} from 'react';
class Slider_content extends Component {
render () {
const { categories, left } = this.props;
return (
<div className="slider__content ">
<div className="slider__wrapper container--vertical">
{categories.map((category, i) => (
<div className="slider__item container" key={i} style={{backgroundColor: category.categoryColor}}>
<div className="slider__item-details">
<span>{category.name}</span>
View Products
</div>
<div className="slider__item-img">
<img src={category.image} class="slider__img"/>
</div>
</div>
))}
</div>
</div>
);
}
}
export default Slider_content;
CSS:
.slider {
margin-top: 3em;
height: 100%;
position: relative;
}
.slider__content {
height: 100%;
width: 100%;
position: relative;
}
.slider__wrapper {
height: 100%;
flex-wrap: wrap;
overflow: hidden;
justify-content: space-between
}
.slider__item {
height: 100%;
margin : 9px;
position: relative;
overflow: hidden;
}
What i am doing wrong in this code, how can i manage to make the slider_content slider slides to left when click the right arrow and to right when click the left arrow??
I don't want the slider slides by 500px per click, it is just for experimenting
i need it to slide accurately to show the next 3 images in right position, i could not do that too!!
Related
I want to show items as flex but still it is showing like a column. What am I doing wrong here?
This is my component :
import React from "react";
import { Link } from "react-router-dom";
import { useSelector } from "react-redux";
import "./Listing.css";
const ProductComponent = () => {
const products = useSelector((state) => state.allProducts.products);
const renderList = products.map((product) => {
const { id, title, image, price, category } = product;
return (
<div className="container">
<div key={id} className="item-box" >
<Link to={`/product/${id}`}>
<div className="image-box">
<img src={image} alt={title} />
</div>
<div className="detail">
<div >{title}</div>
<div >$ {price}</div>
<div >{category}</div>
</div>
</Link>
</div>
</div>
);
});
return <>{renderList}</>;
};
export default ProductComponent;
This is the css file of this component:
.container{
width: 100%;
height: 90vh;
flex-wrap: wrap;
display: flex;
}
.item-box{
border: 2px solid #000;
display: flex;
height: auto;
width: 380px;
padding: 10px;
justify-content: center;
margin: 20px;
}
img{
height: auto;
width: 300px;
}
And finally this is my App.css:
* {
font-family: "Roboto", sans-serif;
padding: 0;
margin: 0;
box-sizing: border-box;
}
Thanks in advance.
I wanna show the items as flex (from left to right) but it is like a column though I defined "display:flex"
You are looping through the array and outputing multiple containers. Each container is display-flex but the problem is that they all have only one child. Move the map inside the container:
return (
<div className="container">
{ products.map((product) => {
const { id, title, image, price, category } = product;
return (
<div key={id} className="item-box" >
<Link to={`/product/${id}`}>
<div className="image-box">
<img src={image} alt={title} />
</div>
<div className="detail">
<div >{title}</div>
<div >$ {price}</div>
<div >{category}</div>
</div>
</Link>
</div>
)
})}
</div>
)
In the style of .container just add flex-direction:coloum
.container{
width: 100%;
height: 90vh;
display: flex;
flex-direction: column;
}
If you want the column in center, then you can append justify-content:center & align-items:center as well.
I have created an image carousel with an active image in the middle and all the images on the side and trying to show the active image on the side by adding a border around the image.
The border is being shown initially, but I am unable to see it after clicking on other images.
ImageDisplay.js:
import React,{useState} from 'react';
import {SideBySideMagnifier} from 'react-image-magnifiers';
import '../CSS/imagedisplay.css';
function ImageDisplay({product}) {
const image = typeof(product.images) ==='object' ? product.images[0].props.src: product.images;
const [current,setCurrent] = useState(image);
const handleClick = (e) =>{
setCurrent(e.target.src);
}
return (
<div className='carousel'>
<div className='images'>
{typeof (product.images)==='object' ? product.images.map( (item,idx) =>
(
<div key={idx.toString()} className='small-images' onClick={handleClick}>
<img className={item.props.src===current ? 'selected': ' '} src= {item.props.src} alt=''/>
</div>
)
) :
( <div className='small-images'><img src={product.images} alt={product.name}/></div>)}
</div>
<div className='container'>
<SideBySideMagnifier className='magnifier' alwaysInPlace={true} imageSrc={current} imageAlt='present' largeImageSrc={current}/>
</div>
</div>
)
}
export default ImageDisplay;
CSS:
.carousel{
display:flex;
}
.images{
height:100vh;
overflow: scroll;
}
.small-images img {
width:5vw;
height:5vw;
object-fit:contain;
margin:20px 20px 20px 0;
display:block;
cursor:pointer;
}
/* .magnifier{
height: 80%;
} */
.magnifier > div {
display: flex;
height:80%;
}
.magnifier>div>img {
max-height: 500px;
max-width: 600px;
margin: 100px;
width: auto !important;
object-fit:contain; /* should be removed from inline styles */
}
.selected{
border:1px solid #F26241;
}
Can anybody help me on this?
Can someone please help me with this problem. I'm creating my personal portfolio website using react.js and bootstrap. I'm using react popupbox package but when I click on that popup using small screen, my picture is not in the middle. How can I change that? And is that even possible using only css?
Declaring popupbox code:
const Portfolio = () => {
const openPopupboxFlappyBird = () => {
const content = (
<>
<img className="portfolio-image-popupbox" src= {flappyBird} alt="Flappy Bird" />
<p>Flappy Bird game written in C#</p>
<a className="hyper-link" onClick={() => window.open("https://github.com/zacikmareek/simpleFlappyBird", "_blank")}>Github link</a>
</>
)
PopupboxManager.open({ content })
}
const popupboxConfigFlappyBird = {
titleBar: {
enable: true,
text: "Flappy Bird"
},
fadeIn: true,
fadeInSpeed: 500
}
Adding image:
return (
<div className="portfolio-wrapper">
<div className="container">
<h1 className="text-lovercase text-center py-5">.portfolio()</h1>
<div className="image-box-wrapper row justify-content-center">
<div className="portfolio-image-box" onClick={openPopupboxFlappyBird}>
<img className="portfolio-image" src={flappyBird} alt="Flappy Bird" />
<div className="overflow"></div>
<FontAwesomeIcon className="portfolio-icon" icon={faSearchPlus} />
</div>
</div>
</div>
<PopupboxContainer {...popupboxConfigFlappyBird} />
</div>
)
And here is my .css:
.portfolio-image-popubox {
width: 45rem;
padding: 0 0.5rem;
}
.hyper-link {
cursor: pointer;
color: var(--secondary-dark);
}
.hyper-link:hover {
color: var(--primary-red);
}
#media(max-width: 768px) {
.portfolio-image-popubox {
width: 100%;
}
}
#media(max-height: 640px) {
.popupbox-wrapper {
height: 100%;
}
.portfolio-image-popubox {
width: 80%;
}
}
This is how it looks like now.
So, is there any possibility to fit whole image to screen?
Thank you
Have you tried to give the image a width:100%; or the w-100 bootstrap class?
If nothing happens, try adding display:block; or display:inline-block; too the img tag as well.
If the img already has an 100% width, you can use the object-fit property, object-fit: contain; or object-fit: cover;
EDIT:
Based on some simple testing on the website that you've provided, by adding to your CSS, it should be fixed.
.portfolio-image-popupbox {
width: 100%;
}
screenshot: https://ibb.co/pXjLwHf
I'd like to show the buttons row direction.
I've given disply:flex but it still shows column.
It should be the button has a first character of the name which is underneath the button
and these buttons should be next to each other.
Not like button on the left and the name on the right.
Would be appreciated if I could get help.
RoomList.js
import React from 'react';
import './RoomList.css';
import PropTypes from 'prop-types';
const RoomList = ({ roomList }) => {
return (
<div>
{roomList.map((room) => {
const firstToChar = room.split('');
const firstChar = firstToChar[0];
return (
<div>
<li className="list">
<div className="room-list">
<button type="submit">{firstChar}</button>
<div>{room}</div>
</div>
</li>
</div>
);
})}
</div>
);
};
RoomList.propTypes = {
roomList: PropTypes.func.isRequired,
};
export default RoomList;
RoomList.css
button {
height: 40px;
min-width: 40px;
display: block;
border-radius: 50%;
margin-bottom: 5px;
}
.room-list {
}
.list {
list-style-type: none;
display: flex;
}
The problem is with the HTML you produce. You produce one list by room. Which is not what you want, you want one list, and one item by room in your list.
button {
height: 40px;
min-width: 40px;
display: block;
border-radius: 50%;
margin-bottom: 5px;
}
.room-list {
}
.list {
list-style-type: none;
display: flex;
}
<div>
<div>
<li class="list">
<div class="room-list">
<button type="submit">K</button>
<div>Kitchen</div>
</div>
</li>
</div>
<div>
<li class="list">
<div class="room-list">
<button type="submit">B</button>
<div>Bathroom</div>
</div>
</li>
</div>
</div>
What you want is:
button {
height: 40px;
min-width: 40px;
display: block;
border-radius: 50%;
margin-bottom: 5px;
}
.room-list {
}
.list {
list-style-type: none;
display: flex;
}
<div>
<div>
<li class="list">
<div class="room-list">
<button type="submit">K</button>
<div>Kitchen</div>
</div>
<div class="room-list">
<button type="submit">B</button>
<div>Bathroom</div>
</div>
</li>
</div>
</div>
So you actually want:
const RoomList = ({ roomList }) => {
return (
<div>
<div>
<li className="list">
{roomList.map((room) => {
const firstToChar = room.split('');
const firstChar = firstToChar[0];
return (
<div className="room-list">
<button type="submit">{firstChar}</button>
<div>{room}</div>
</div>
);
})}
</li>
</div>
</div>
);
};
The flex should be on the room list instead
Hello so i use a portal Component that looks like this that is used to create "modals"
export const ModalWindow = (props: RenderableProps<Props>) => {
if (!props.display) {
return null;
}
return (
<Portal parentNode={props.parentNode} renderOnMount={true}>
<div id='modal' className={props.largeModal ? 'modal-large' : 'modal-small'}>
{props.children}
</div>
</Portal>
)
}
Then i have this component that i then render inside that modal
export const ShowInformation = (props: RenderableProps<Props>) => {
return (
<div className='blur-out-menu'>
<div className='information-content'>
<span className='information-title'>Show Information?</span>
<span className='information-text'>Click check button to show information</span>
<div className='button-section'>
<div className='decline-button' onClick={() => props.onShow(false)}>
<CancelButton />
</div>
<div className='check-button' onClick={() => props.onShow(true)}>
<CheckButton />
</div>
</div>
</div>
</div>
);
};
what is important here is the blur-out-menu that i just want to use to blur out everything except the modal but i cant figure it out either it just covers the same area as the modal or if i put position fixed it messes it up totally and nothing inside the modal keeps in place. is there any nice way of doing this?
here is the css for the blur-out-menu
.blur-out-menu {
background-color: rgba(0, 0, 0, 0.25);
height: 100%;
width: 100%;
position: absolute;
top: 0;
left: 0;
z-index: 4;
}
the modal got z-index 5 so it is above this blur out
here is the modal css as well
.modal-small {
background-color: #1E2933;
top: 25%;
left: 5%;
width: 90%;
height: 30%;
border-radius: 10px;
z-index: 5;
}
In .blur-out-menu change height property to 100vh and width property to 100vw
This should to the trick.