React Onmouseover Suggestion - css

I'm learning build website using react and bootstrap css,
i have carousel, and separated navigation.
below example code of my carousel
class Home extends React.Component {
mousehover() {
... ???? .....
};
render() { return (
<div className="row">
<div id="carouselExampleIndicators" className="carousel slide col-9" data-ride="carousel">
<div className="carousel-inner" role="listbox">
<div className="carousel-item active">
<img className="d-block img-fluid" src="http://northdelawhere.happeningmag.com/wp-content/uploads/banner_sample300x300.jpg"
alt="First slide" />
</div>
<div className="carousel-item">
<img className="d-block img-fluid" src="http://www.raymiller.cc/thumbnail/exterior-beadboard-paneling-4-texture-plus-indoor-outdoor-siding-panel-beadboard-oak-sample-300-x-300.jpg"
alt="Second slide" />
</div>
<div className="carousel-item">
<img className="d-block img-fluid" src="..." alt="Third slide" />
</div>
</div>
<a className="carousel-control-prev" href="#carouselExampleIndicators" role="button" data-slide="prev">
<span className="carousel-control-prev-icon" aria-hidden="true"></span>
<span className="sr-only">Previous</span>
</a>
<a className="carousel-control-next" href="#carouselExampleIndicators" role="button" data-slide="next">
<span className="carousel-control-next-icon" aria-hidden="true"></span>
<span className="sr-only">Next</span>
</a>
</div>
<div className="col-3">
<ul className="flex-column">
<li data-target="#carouselExampleIndicators" data-slide-to="0" onmouseover={this.mousehover}>one</li>
<li data-target="#carouselExampleIndicators" data-slide-to="1">two</li>
<li data-target="#carouselExampleIndicators" data-slide-to="2">three</li>
</ul>
</div>
</div>
)}
}
React.render(<Home />, document.getElementById('root'));
i'm trying create event for my list using onmousehover, but failed.
anyone can help me for give clue / example for onmousehover event which will slide to target carousel (data-slide-to) ?
thank you very much.

Have a look at the SyntheticEvent section of the React docs, it explains how to use events like onMouseEnter and onMouseLeave in React:
Your event handlers will be passed instances of SyntheticEvent, a
cross-browser wrapper around the browser's native event. It has the
same interface as the browser's native event, including
stopPropagation() and preventDefault(), except the events work
identically across all browsers.
That said, depending on your use case, you be better off implementing the hover effect using CSS's :hover pseudo-class.

Related

Why has making my carousel narrower created glitchy transition between slides?

I'm want my carousel to be a certain size (not sure what size until I play about, but certainly not width: 100%) and also to be centred horizontally in the page.
My new CSS rule has made the carousel smaller and central, but now the slides do not move automatically. The ol with class "carousel-indicators" works fine, so I can select and successfully move to each slide manually.
This same CSS has seemingly removed the click functionality of my next/prev arrows. Even stranger, when I click my next arrow, the page 'smooth-scrolls' down the page a little. Thanks in advance :)
Here is the code....
HTML:
<div id="event-carousel" class="carousel slide" data-right="carousel">
<ol class="carousel-indicators">
<li data-target="#event-carousel" data-slide-to="0"></li>
<li data-target="#event-carousel" data-slide-to="1"></li>
<li data-target="#event-carousel" data-slide-to="2"></li>
<li data-target="#event-carousel" data-slide-to="3"></li>
<li data-target="#event-carousel" data-slide-to="4"></li>
</ol>
<div class="carousel-inner" roll="listbox">
<div class="carousel-item active">
<img class="d-block w-100" src="./recources/images/pioneeringSpirit.png" alt="Temporary structures built on the Pioneering Spirit catamaran">
<div class="carousel-caption">
<h3>Pioneering Spirit</h3>
<p>Weeks at sea produced thousands of square meters of temporary hospitality structures.</p>
</div>
</div>
<div class="carousel-item">
<img class="d-block w-100" src="./recources/images/rugbyWorldCup.png" alt="Main structure for England's Rugby World Cup.">
<div class="carousel-caption">
<h3>Rugby World Cup</h3>
<p>Twickenham is part of the White Rose Crew calander, but this year was special.</p>
</div>
</div>
<div class="carousel-item">
<img class="d-block w-100" src="./recources/images/thales.png" alt="A three story structure for Farnborough Airshow.">
<div class="carousel-caption">
<h3>Thales</h3>
<p>Our favourite biannual build of the worlds largest airshow.</p>
</div>
</div>
<div class="carousel-item">
<img class="d-block w-100" src="./recources/images/masterpiece.png" alt="Masterpiece Arts Fair, Chelsea.">
<div class="carousel-caption">
<h3>Masterpiece</h3>
<p>We are proud to be an integral part of this incredible transformation year in, year out.</p>
</div>
</div>
<div class="carousel-item">
<img class="d-block w-100" src="./recources/images/fieldHospital.jpg" alt="Emergancy hospital built in the Pricipality Stadium.">
<div class="carousel-caption">
<h3>Emergancy Covid-19 Field Hospital</h3>
<p>Helping turn The Pricipality Stadium into Wales largest hospital in just 10 days.</p>
</div>
</div>
<a class="carousel-control-prev" href="#event-carousel" role="button" data-slide="prev">
<span class="carousel-control-prev-icon"></span>
<span class="sr-only">Previous</span>
</a>
<a class="carousel-control-next" href="#event-carousel" role="button" data-slide="next">
<span class="carousel-control-next-icon"></span>
<span class="sr-only">next</span>
</a>
</div>
</div>
CSS:
.carousel-inner {
margin: auto;
width: 55%;
height: auto;
}
JS:
$(document).ready(() => {
$('#event-carousel').carousel({
interval: 8000
});
$('#event-carousel').carousel('cycle');
});

I have a mistake in ASP.NET MVC

Index.cshtml
#using eCommerceStatic.Models;
#model IEnumerable<ProductModel>
#{
//ViewBag.Title = "Index";
}
<!--Carousel Wrapper-->
<div id="carousel-example-1z" class="carousel slide carousel-fade pt-4" data-ride="carousel">
<!--Indicators-->
<ol class="carousel-indicators">
<li data-target="#carousel-example-1z" data-slide-to="0" class="active"></li>
<li data-target="#carousel-example-1z" data-slide-to="1"></li>
<li data-target="#carousel-example-1z" data-slide-to="2"></li>
</ol>
<!--/.Indicators-->
<!--Slides-->
<div class="carousel-inner" role="listbox">
<!--First slide-->
<div class="carousel-item active">
<div class="view" style="background-image: url('https://mdbootstrap.com/img/Photos/Horizontal/E-commerce/8-col/img%282%29.jpg'); background-repeat: no-repeat; background-size: cover;">
<!-- Mask & flexbox options-->
<div class="mask rgba-black-strong d-flex justify-content-center align-items-center">
<!-- Content -->
<div class="text-center white-text mx-5 wow fadeIn">
<h1 class="mb-4">
<strong>Learn Bootstrap 4 with MDB</strong>
</h1>
<p>
<strong>Best & free guide of responsive web design</strong>
</p>
<p class="mb-4 d-none d-md-block">
<strong>
The most comprehensive tutorial for the Bootstrap 4. Loved by over 500 000 users. Video and
written versions
available. Create your own, stunning website.
</strong>
</p>
<a target="_blank" href="https://mdbootstrap.com/education/bootstrap/" class="btn btn-outline-white btn-lg">
Start
free tutorial
<i class="fas fa-graduation-cap ml-2"></i>
</a>
</div>
<!-- Content -->
</div>
<!-- Mask & flexbox options-->
</div>
</div>
<!--/First slide-->
<!--Second slide-->
<div class="carousel-item">
<div class="view" style="background-image: url('https://mdbootstrap.com/img/Photos/Horizontal/E-commerce/8-col/img%283%29.jpg'); background-repeat: no-repeat; background-size: cover;">
<!-- Mask & flexbox options-->
<div class="mask rgba-black-strong d-flex justify-content-center align-items-center">
<!-- Content -->
<div class="text-center white-text mx-5 wow fadeIn">
<h1 class="mb-4">
<strong>Learn Bootstrap 4 with MDB</strong>
</h1>
<p>
<strong>Best & free guide of responsive web design</strong>
</p>
<p class="mb-4 d-none d-md-block">
<strong>
The most comprehensive tutorial for the Bootstrap 4. Loved by over 500 000 users. Video and
written versions
available. Create your own, stunning website.
</strong>
</p>
<a target="_blank" href="https://mdbootstrap.com/education/bootstrap/" class="btn btn-outline-white btn-lg">
Start
free tutorial
<i class="fas fa-graduation-cap ml-2"></i>
</a>
</div>
<!-- Content -->
</div>
<!-- Mask & flexbox options-->
</div>
</div>
<!--/Second slide-->
<!--Third slide-->
<div class="carousel-item">
<div class="view" style="background-image: url('https://mdbootstrap.com/img/Photos/Horizontal/E-commerce/8-col/img%285%29.jpg'); background-repeat: no-repeat; background-size: cover;">
<!-- Mask & flexbox options-->
<div class="mask rgba-black-strong d-flex justify-content-center align-items-center">
<!-- Content -->
<div class="text-center white-text mx-5 wow fadeIn">
<h1 class="mb-4">
<strong>Learn Bootstrap 4 with MDB</strong>
</h1>
<p>
<strong>Best & free guide of responsive web design</strong>
</p>
<p class="mb-4 d-none d-md-block">
<strong>
The most comprehensive tutorial for the Bootstrap 4. Loved by over 500 000 users. Video and
written versions
available. Create your own, stunning website.
</strong>
</p>
<a target="_blank" href="https://mdbootstrap.com/education/bootstrap/" class="btn btn-outline-white btn-lg">
Start
free tutorial
<i class="fas fa-graduation-cap ml-2"></i>
</a>
</div>
<!-- Content -->
</div>
<!-- Mask & flexbox options-->
</div>
</div>
<!--/Third slide-->
</div>
<!--/.Slides-->
<!--Controls-->
<a class="carousel-control-prev" href="#carousel-example-1z" role="button" data-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="carousel-control-next" href="#carousel-example-1z" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
<!--/.Controls-->
</div>
<!--/.Carousel Wrapper-->
<!--Main layout-->
#Html.Partial("_GetCategories")
<main>
<div class="container">
<!--Navbar-->
<!--/.Navbar-->
#Html.Partial("_ProductList",Model)
</div>
</main>
<!--Main layout-->
HomeController.cs
public PartialViewResult _GetCategories()
{
return PartialView(_context.Categories.ToList());
}
_GetCategories.cshtml
#model IEnumerable<eCommerceStatic.Entity.Category>
eCommerceStatic.Entity
<nav class="navbar navbar-expand-lg navbar-dark mdb-color lighten-3 mt-3 mb-5">
<!-- Navbar brand -->
<span class="navbar-brand">Kategoriler :</span>
<!-- Collapse button -->
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#basicExampleNav"
aria-controls="basicExampleNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<!-- Collapsible content -->
<div class="collapse navbar-collapse" id="basicExampleNav">
<!-- Links -->
#foreach (var category in Model)
{
<ul class="navbar-nav mr-auto">
<li class="nav-item">
<a class="nav-link" href="/Home/List/#category.Id">#category.Name</a>
</li>
</ul>
}
<!-- Links -->
<form class="form-inline">
<div class="md-form my-0">
<input class="form-control mr-sm-2" type="text" placeholder="Search" aria-label="Search">
</div>
</form>
</div>
<!-- Collapsible content -->
</nav>
Error
Additional information: The model item passed into the dictionary is of type 'System.Collections.Generic.List1[eCommerceStatic.Models.ProductModel]', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable1[eCommerceStatic.Entity.Category]'
How can I fix this?
It is because, your Partial View which is:
_GetCategories.cshtml requires #model IEnumerable<eCommerceStatic.Entity.Category>
but your Index.cshtml which is your Main View in this case, requires
#model IEnumerable<ProductModel>
So, you should be using #model IEnumerable<ProductModel> in your _GetCategories.cshtml
In these cases, consider using a common model class. You can do something similar to this:
Create a new Model class,
Create List<ProductModel> and List<Category> properties.
public class ProductsAndCategories
{
public List<ProductModel> Products { get; set; }
public List<Category> Categories { get; set; }
}
So in your Index :
public IActionResult Index()
{
var model = new ProductsAndCategories
{
//Define your IEnumerable<ProductModel>
//Below is an example...
Products = _context.ProductModel.ToList()
};
return View(model);
}
And in your _GetCategories :
public PartialViewResult _GetCategories()
{
var model = new ProductsAndCategories
{
Categories = _context.Categories.ToList()
};
return PartialView(model);
}
CSHTML
Index.cshtml:
#model ProductsAndCategories
and in your _GetCategories.cshtml:
#model ProductsAndCategories
<nav class="navbar navbar-expand-lg navbar-dark mdb-color lighten-3 mt-3 mb-5">
<!-- Navbar brand -->
....

How Do I Fix the Carousel Slider Controls?

I'm trying to setup a CSS carousel, when I wrote the code the automatic sliding seems to work okay, although it seems little buggy. However the main issue is the prev and next controls don't work properly. Every time you click one of them they always start you from the active-item image so you can never fully click through the images.
<body>
<div class="container">
<div class="container-fluid">
<div class="row">
<div class="col-sm-12">
<div id="my-slider" class="carousel slide" data-ride="carousel">
<div class="carousel-inner" role="listbox">
<div class="item active">
<img src="images/parvazlogo.jpg" alt="program" />
<div class="carousel-caption">
<h1></h1>
</div>
</div>
<div class="item">
<img src="images/program1.jpg" alt="programming image" />
<div class="carousel-caption">
<h1>ParwazTech Will Bring your Ideas To Life!</h1>
</div>
</div>
<div class="item">
<img src="images/innovation.jpg" alt="innovation" />
<div class="carousel-caption">
<h1>Learn More about Us</h1>
</div>
</div>
<div class="item">
<img src="images/office.jpg" alt="deal struck" />
<div class="carousel-caption">
<h1>Start looking at deals now!</h1>
</div>
</div>
<a class="left carousel-control" href="#my-slider" role="button" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="right carousel-control" href="#my-slider" role="button" data-slide="next">
<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
<span class="sr-only">next</span>
</a>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
#MatiasFernandezMartinez
https://youtu.be/7Hr-EBEpVJ0 this is a video of the problem just to prove it is happening. As you can see the bottom three buttons work fine but the two left and right buttons bring up the problem I described
I'm assuming the problem is with my bootstrap or my jquery since the code does not bring you all problems

Accessing <img> inside nested <div> in CSS

I'm trying to fill carousel-background image fill carousel. But I'm not able to access tag from css.
<div id="carouselSlider" class="carousel slide" data-ride="carousel">
<ol class="carousel-indicators">
<!-- data-slide-to part -->
</ol>
<div class="carousel-inner">
<div class="carousel-item active">
<div class="carousel-background"><img src="img/portfolio/fullsize/1.jpg"></div>
<div class="carousel-container">
<div class="carousel-caption">
<h2>We are xyz</h2>
<p>We help you to blah blah blah!</p>
Get Started
</div> <!--carousel-content-->
</div> <!--carousel-container-->
</div> <!--carousel-item-->
<div class="carousel-item">
<!-- similar content with <img>-->
</div> <!--carousel-item-->
<div class="carousel-item">
<!-- similar content with <img>-->
</div> <!--carousel-item-->
</div> <!--carousel-inner-->
<a class="carousel-control-prev" href="#carouselSlider" role="button" data-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="carousel-control-next" href="#carouselSlider" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div> <!--carousel-->
CSS File:
#carouselSlider .carousel-inner .carousel-item .carousel-background img{
width: 100%;
height:400px;
}
I'm not able to edit image. Also is there a way to fill image in carousel without stretching it?
You can add classes to images. That line of code should look like
<div class="carousel-background"><img class="whateveryouwant" src="img/portfolio/fullsize/1.jpg"></div>
You're trying to navigate through your nested structure using classes but that's not how it works. Because you only have one image inside your carouselSlider div you could simply access it using:
#carouselSlider img {<your css here>}
But this will probably break when you have more images in there. If you can change that HTML you should probably add a class to your img or an id to to one of those inner divs and access it directly.
To avoid the image getting stretched check out the "background-size" CSS property. Either 'cover' or 'contain' should do it for you.

Bootstrap Image Slider Controls Does Not Work Properly

I'm working on a project in Bootstrap and I have added a simple image carousel with controls but the problem is that the controls does not work.. See my site here
As you can see you can not press on next and previous buttons to see other images. Here's my code:
<div class="row">
<div class="container">
<div class="col-md-3">
</div>
<div class="col-md-6">
<div id="myCarousel" class="carousel slide" data-ride="carousel">
<!-- Indicators -->
<ol class="carousel-indicators">
<li data-target="#myCarousel" data-slide-to="0" class="active"></li>
<li data-target="#myCarousel" data-slide-to="1"></li>
<li data-target="#myCarousel" data-slide-to="2"></li>
</ol>
<!-- Wrapper for slides -->
<div class="carousel-inner">
<div class="item active">
<img src="images/slideshow/1.jpg" alt="Los Angeles" style="width:100%;">
<div class="carousel-caption">
<h3>Los Angeles</h3>
<p>LA is always so much fun!</p>
</div>
</div>
<div class="item">
<img src="images/slideshow/2.jpg" alt="Chicago" style="width:100%;">
<div class="carousel-caption">
<h3>Chicago</h3>
<p>Thank you, Chicago!</p>
</div>
</div>
<div class="item">
<img src="images/slideshow/3.jpg" alt="New York" style="width:100%;">
<div class="carousel-caption">
<h3>New York</h3>
<p>We love the Big Apple!</p>
</div>
</div>
</div>
<!-- Left and right controls -->
<a class="left carousel-control" href="#myCarousel" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left"></span>
<span class="sr-only">Previous</span>
</a>
<a class="right carousel-control" href="#myCarousel" data-slide="next">
<span class="glyphicon glyphicon-chevron-right"></span>
<span class="sr-only">Next</span>
</a>
</div>
</div>
<div class="col-md-3">
</div>
</div>
</div>
Basically I have not found any kind of mistake in this code ,so if you know what is going wrong please let me know... thanks!
Your code has no problem. But You have used a older version of jQuery. Please update with newer version.
http://take.ms/Rbwmf
You can use this version. It is working perfectly with your code.
<script src="https://code.jquery.com/jquery-2.2.4.min.js"></script>
Thanks
You use the id="myCarousel" several time on this page.
You can only have ONE UNIQUE id per page. Removing the other id="myCarousel" fixes your issue.
Some additional info on IDs:
IDs are here in order for Javascript to target element quite easily. But while they make targeting element with JS easy, they need to be unique otherwise, the script won't be able to know which ID to target. There are many other way to target element with JS but this one stay one of the easiest one.
Small advice: even if you can, don't create IDs for CSS since they are not meant for that. Leave the IDs for use in JS. That will help to keep your code clean consistent.

Resources