Active Image in Carousel - css

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?

Related

How do I achieve this CSS effect on the Image?

I am using the style component library and am trying to blur the sides of an image like in the following example:
Does anyone have any idea on how to do this? This is the code that I have for the component that I am trying to achieve this on:
import React from "react";
import styled from "styled-components";
const StyledTopicItem = styled.div`
position:relative;
height: 2.5rem;
border: 1px solid black;
border-radius: 10px;
display: flex;
align-items: center;
cursor: pointer;
height:20vh;
justify-content:center
`;
const Topic = styled.div`
position:absolute;
bottom:1px;
font-weight:bold;
`
interface topicItemProps {
topic: string;
setSelectedTopic: (value: string) => void;
}
export const TopicItem = ({ topic, setSelectedTopic }: topicItemProps) => {
return (
<StyledTopicItem
onClick={(e: any) => {
setSelectedTopic(e.target?.innerText);
}}
>
<img alt={""} src={'https://images.unsplash.com/photo-1514921674539-8b1710289b0d?crop=entropy&cs=srgb&fm=jpg&ixid=MnwzNDE2fDB8MXxyYW5kb218fHx8fHx8fHwxNjQyNjg0OTgz&ixlib=rb-1.2.1&q=85'} height={150} width={250}/> <br/>
<Topic>{topic}</Topic>
</StyledTopicItem>
);
};
You could use object-fit, background and backdrop-filter . eventually aspect-ratio can help even your boxes if you have more than one and CSS var() to simplify your CSS.
example
img {
display:block;
width:100%;
height:100%;
object-fit:contain;
backdrop-filter: blur(3px);
}
div{
background:var(--bg) center center / cover transparent;
aspect-ratio: 3 / 2;
border:solid;
height:200px;
}
body {
display:flex;
flex-wrap:wrap;
gap:1em;
}
<div class style="--bg:url(https://picsum.photos/id/59/200/200)" >
<img src=https://picsum.photos/id/59/200/200 >
</div>
<div class style="--bg:url(https://picsum.photos/id/58/200/200)" >
<img src=https://picsum.photos/id/58/200/200 >
</div>
<div class style="--bg:url(https://picsum.photos/id/57/200/200)" >
<img src=https://picsum.photos/id/57/200/200 >
</div>

Regarding applying animation to an image using dynamic CSS styles in React

I'm new to React. I have this image ("c-tile-img") inside a div ("c-tile-holder") and what I want to do is when I hover over the div or the image element I want to translate on Y-axis slightly like a hover effect. I used React useState hook to achieve this but when I run it nothing is triggered. Here is what I've so far...
**
Tile.jsx
**
const Tile = () => {
const[isMousedOver, setMouseOver] = useState(false);
function handleMouseOver() {
setMouseOver(true);
}
function handleMouseOut() {
setMouseOver(false);
}
return (
<React.Fragment>
<div className="c-tiles">
<a href="/work/help-scout/" className="c-tile c-tile-hs" aria-label="Help Scout Case Study"
style={{translate: isMousedOver ? '50': '0'}}
onMouseOut={handleMouseOut}
onMouseOver={handleMouseOver}>
<span className="c-tile-category">Mobile</span>
<h2 className="c-tile-title">Help Scout</h2>
<div className="c-tile-holder">
<img className="c-tile-img c-tile-img-hs lazy loaded" alt="Help Scout" aria-label="Help Scout image" data-ll-status="loaded"
src={headshot}/>
</div>
</a>
My CSS File
Tile.css
.c-tile-holder {
position: relative;
max-width: 100%;
margin: 0 auto;
text-align: center;
}
.c-tile-img-hs {
max-width: 80%;
}
.c-tile-img {
position: relative;
transition: all .4s ease-in-out;
max-width: 100%;
display: inline-block;
}
img {
vertical-align: middle;
}
img {
border-style: none;
}

How to give animation on width change with different classname but for same component

what is the best practice to show/hide the side menu with animation? The way I implement works fine but I can't implement the animation. I also shared images so everyone can have some idea.
The answer might be easy but I couldn't fully understand the toggle class efficiently. If I would I should be able to implement transition just by changing the width from the same classname.
Also I am getting this error on console: Received false for a non-boolean attribute className.
React code ;
const handleSize = () => {
setOpen(!open); }; return (
<div
className={"sideBar" + `${open ? " sideBar__show" : " sideBar__hide"}`}
>
<div className="sideBar__header">
<div className="menu_buttons" onClick={handleSize}>
<MenuIcon className="sideBar_icon" />
<p className={!open && "sideBar_hide__content"}>Menu</p>
</div>
</div>
<hr className="sideBar__divider" />
<div className="sideBar__content">
{sideBarContent.map((item) => {
return (
<div className="menu_buttons" key={item.name}>
<item.icon />
<p className={!open && "sideBar_hide__content"}>{item.name}</p>
</div>
);
})}
</div>
<hr className="sideBar__divider" />
<div className="sideBar__footer">
<Avatar>{firstLetter}</Avatar>
<p className={!open && "sideBar_hide__content"}>{adminName}</p>
</div>
</div> ); };
CSS;
.sideBar {
position: fixed;
left: var(--sidebar-left-margin);
height: max-content;
top: calc(var(--header-height) + 10px);
bottom: 10px;
border-radius: 10px;
background-color: var(--second-color);
display: flex;
flex-direction: column;
align-items: center;
padding: 10px 5px;
border: 1px solid var(--main-color);
/* transition: all ease-in 1s; */
}
.sideBar__show {
width: var(--sidebarOpen-width);
}
.sideBar_hide {
width: var(--sidebarClose-width);
}
.sideBar_hide__content {
display: none;
}
Not sure what is best practice, this is my currently approach:
const handleSize = () => setOpen(!open);
const sideBarClasses = open ? "sideBar sideBar_show : "sideBar sideBar_hide;
<div className="sideBar__header">
<div className={sideBarClasses}>

Display flex has no influence - ReactJS

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.

Fit image to small popupbox - React.js + Bootstrap

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

Resources