In my html page, I have an external javascript code, that causes a modal to pop up when a project in my html class is clicked. the projects are specified through the li class attribute. I now wish to chance this, so the modal instead pops up when a span id element is clicked. Therfor I have revisited by Javascript code, and changed the li class-attribute (in this case .Project) into the span id attribute (#PopUp. Unfortunately I have not been able to make my code work, through that. Is anyone able to see where I go wrong?
/* Javascript */
window.onload = function() {
span = document.querySelectorAll("#PopUp");
document.querySelectorAll("#PopUp").forEach(LIelm => {
LIelm.addEventListener('click', showHideModal)
})
};
function showHideModal(e) {
if (!e.target.parentNode.matches('#PopUp , .modal-content')) return
e.preventDefault();
let currentParent = e.target.parentNode;
if (currentParent.matches('#PopUp')) {
document.getElementById(currentParent.dataset.modal).style.display = "block";
} else {
currentParent.parentNode.style.display = "";
}
}
/* HTML */
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
<div class="content">
<div id="contact">
About Contact: c.thornval#live.dk 0045 7158 0488
<br>
<br>
</div>
<ul style="list-style: none;">
<li class="Project" data-modal="myModal_1">
<span id="myBtn_1">Irma Type</span>
<span id="year">2019</span>
<div class="Describtion">
<span id="PopUp">Images</id>
<p style="display:none;">Typedesign<br></p>
</div>
<div id="myModal_1" class="modal">
<div class="modal-content">
<div id="demo" class="carousel slide" data-ride="carousel">
<!-- The slideshow -->
<div class="carousel-inner">
<div class="carousel-item active">
<img src="Images/Lirma/type.jpg" alt="img" width="100%">
</div>
<!-- Left and right controls -->
<a class="carousel-control-prev" href="#demo" data-slide="prev">
<span class="carousel-control-prev-icon"></span>
</a>
<a class="carousel-control-next" href="#demo" data-slide="next">
<span class="carousel-control-next-icon"></span>
</a>
</div>
<p>Some text in the Modal...</p>
</div>
</div>
</div>
</li>
You have a couple of problems, first you cannot use an id because it seems like there would be multiple span elements and id's should be unique, secondly you are using the wrong selectors to determine wether the clicked item is a child of a parent containing a modal and your clicked element is now one level deeper.
Change you javascript code this:
window.onload = function() {
const span = document.querySelectorAll(".PopUp");
span.forEach(LIelm => {
LIelm.addEventListener('click', showHideModal)
})
};
function showHideModal(e) {
const projectNode = e.target.parentNode.parentNode;
if (!projectNode.matches('.Project, .modal-content')) return
e.preventDefault();
if (projectNode.matches('.Project')) {
document.getElementById(projectNode.dataset.modal).style.display = "block";
} else {
projectNode.parentNode.style.display = "";
}
}
Then change #PopUp to .PopUp
...
<li class="Project" data-modal="myModal_1">
<span id="myBtn_1">Irma Type</span>
<span id="year">2019</span>
<div class="Describtion">
<span class="PopUp">Images</id>
<p style="display:none;">Typedesign<br></p>
</div>
<div id="myModal_1" class="modal">
<div class="modal-content">
<div id="demo" class="carousel slide" data-ride="carousel">
<!-- The slideshow -->
<div class="carousel-inner">
<div class="carousel-item active">
<img src="Images/Lirma/type.jpg" alt="img" width="100%">
</div>
<!-- Left and right controls -->
<a class="carousel-control-prev" href="#demo" data-slide="prev">
<span class="carousel-control-prev-icon"></span>
</a>
<a class="carousel-control-next" href="#demo" data-slide="next">
<span class="carousel-control-next-icon"></span>
</a>
</div>
<p>Some text in the Modal...</p>
</div>
</div>
</div>
</li>
...
Related
I am very new to web dev and i am trying to resolve this issue from quite some time, please help me with this,
I have implemented a series of verticle slides each slide contains 10 images and every time i reach bottom i call next images from api call. now i wish to print no. of slide i am presently active on I used below code for it but this way on going to top or below value of slide no. increments and finally becomes constant.
<div class="left">
{{slideno}}
</div>
<div v-for="(images, index) in slides"
:key="index" >{{setslideNumber(index)}}
<div class="container read">
<div
class="col-md-offset-1 col-md-11 col-sm-2 col-xs-12 reader-section"
>
<div
id="carousel-pager"
class="carousel slide "
data-ride="carousel"
data-interval="1000"
>
<div class="carousel-inner vertical">
<div class=" item" style="object-fit: fill;">
<div
v-for="(image, index) in images"
:key="index"
class="section"
style="color:#fff"
>
<img
:src="
image
"
class="img-responsive"
data-target="#carousel-main"
data-slide-to="0"
width:100
/>
</div>
<div v-if="images.length" v-observe-visibility="handleScrolledToBottom"></div>
</div>
</div>
<a
class="left carousel-control"
href="#carousel-pager"
role="button"
data-slide="prev"
>
<span
class="glyphicon glyphicon-chevron-up"
aria-hidden="true"
></span>
<span class="sr-only">Previous</span>
</a>
<a
class="right carousel-control"
href="#carousel-pager"
role="button"
data-slide="next"
>
<span
class="glyphicon glyphicon-chevron-down"
aria-hidden="true"
></span>
<span class="sr-only">Next</span>
</a>
</div>
</div>
</div>
</div>
</div>
methods: {
setSlideNumber(index){
this.slideno=index+1;
},
}
what value of sliden0 i am getting: 123....10
what i need the value of slide that is visible,
This is my component.ts file, followed by the code for the Carousel:
`
public dummyData = [
{
title: '50 Cent',
text: 'Get Rich or Die Tryin'
},
{
title: 'Dr. Dre',
text: '2001'
},
{
title: 'Eminem',
text: 'Recovery'
},
{
title: '2pac',
text: 'All Eyez On Me'
},
{
title: 'The Notorious B.I.G',
text: 'Life After Death'
}
];
<div id="carouselExampleControls" class="carousel slide" data-ride="carousel">
<div class="carousel-inner">
<div class="carousel-item active" *ngFor="let dums of dummyData">
<div class="row">
<div class="card col-md" id="card">
<div class="card-body text-center">
<div class="hover-me">view on github</div>
<h4 class="card-title">{{dums.title}}</h4>
<div class="card-text">{{dums.text}}</div>
</div>
</div>
<div class="card col-md">
<!-- not filled yet -->
</div>
<div class="card col-md">
<!-- not filled yet -->
</div>
</div>
</div>
</div>
<a class="carousel-control-prev" href="#carouselExampleControls" 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="#carouselExampleControls" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
I have an array of objects called 'dummyData', and the code above must create carousel items(with three boxes each), as long as the array 'dummyData' has objects within.
But the problem is, when another item is created(after iteration over first three objects), it has the class 'active' too, due to which there the slider does not function.
Is there a way to remove an HTML class code after a few iterations in the ngFor loop?
I would like a carousel that fills about half of the window. I've been reading through the documentation https://getbootstrap.com/docs/4.1/components/carousel/ and a following a youtube tutorial for help https://youtu.be/9cKsq14Kfsw?t=3510. My images fill the entire page plus more (when scrolled down) and I can't figure out how to make it smaller other than setting a fixed height in CSS which makes the image look squashed.
Here is my code
html, body {
width: 100%;
height: 100%;
}
.carousel-inner img {
width: 100%;
height: 100%;
}
<!-- Image carousel -->
<div id="slides" class="carousel slide" data-ride="carousel">
<!-- Carousel images -->
<div class="carousel-inner">
<div class="carousel-item active">
<img src="img/home-1.png" />
<div class="carousel-caption">
<h1 class="display-2">Garnet Home Inspections</h1>
</div>
</div>
<div class="carousel-item">
<img src="img/home-2.png" />
<div class="carousel-caption">
<h1 class="display-3">Service Area</h1>
<h3>I travel all over the capital Region</h3>
<button type="button" class="btn btn-outline-light btn-lg">SET UP AN APPOINTMENT</button>
</div>
</div>
<div class="carousel-item">
<img src="img/home-3.png" />
<div class="carousel-caption">
<!-- put content here -->
</div>
</div>
</div>
<!-- Carousel buttons-->
<a class="carousel-control-prev" href="#slides" role="button" data-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="sr-only">Previous</span> <!-- Screenreaders only -->
</a>
<a class="carousel-control-next" href="#slides" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span> <!-- Screenreaders only -->
</a>
</div>
Thank you in advance :)
If anyone needs more information/code please let me know.
I want to control the scroll of this carousel using menu bar where there are buttons 1,2,3,4,5 when I click them the carousel should slide to 2nd slide or 3rd slide like that.
I have used HTML, Bootstrap, CSS.
<div class="container-fluid">
<div class="row" id="row1">
<div class="col-sm-12" style="top: 10%; bottom: 50%;">
<h1>AS</h1>
</div>
</div>
<div class="row" id="row2">
<div class="col-sm-4" style="top: 10%; bottom: 50%; background-color: white; height: 7.4vh">
<h1 style="color: black">AS</h1>
</div>
<div class="col-sm-8" style="top: 10%; bottom: 50%; background-color: black">
<div class="nav">
<ul>
<li class="contact">1</li>
<li class="contact1">2</li>
<li class="about">3</li>
<li class="about1">4</li>
<li class="tutorials">5</li>
</ul>
</div>
</div>
</div>
<div class="row" id="row3">
<div id="myCarousel" class="carousel slide" data-ride="carousel">
<!-- Wrapper for slides -->
<div class="carousel-inner" role="listbox" style="vertical-align: top; position: absolute; background-color:green">
<div class="item active" id="one">
<h1>ABC</h1>
<div class="item" id="two">
<img src="img/B.jpg" alt="Chania">
</div>
<div class="item" id="three">
<img src="img/C.jpg" alt="Flower">
</div>
<div class="item" id="four">
<img src="img/C.jpg" alt="Flower">
</div>
<div class="item" id="five">
<img src="img/C.jpg" alt="Flower">
</div>
</div>
<!-- Left and right controls -->
<a class="left carousel-control" href="#myCarousel" role="button" data-slide="prev">
<span class="glyphicon glyphicon glyphicon-menu-left" aria-hidden="true"></span>
</a>
<a class="right carousel-control" href="#myCarousel" role="button" data-slide="next">
<span class="glyphicon glyphicon glyphicon-menu-right" aria-hidden="true"></span>
</a>
</div>
</div>
<div class="row" id="row4">
<div class="col-sm-12" style="top: 10%; bottom: 50%;">
<button class="button" onclick="Contact">Contact</button>
</div>
</div>
</div>
I'm not sure... Please check. Is it what you want to achieve?
You can place images in different slides.
Then use the .click() method to handle the click JavaScript event.
And call theĀ .carousel(number) method:
Cycles the carousel to a particular frame (0 based, similar to an array).
See also:
the .eq() method
Reduce the set of matched elements to the one at the specified index.
the .index() method
If no argument is passed to the .index() method, the return value is an integer indicating the position of the first element within the jQuery object relative to its sibling elements.
the .find() method
Get the descendants <...> filtered by a selector <...>
the .children() method
Get the children of each element in the set of matched elements, optionally filtered by a selector.
the .parent() method
<...> traverses to the immediate parent of each of these elements in the DOM tree and constructs a new jQuery object from the matching elements.
<...> travels a single level up the DOM tree.
the .prev() method
Get the immediately preceding sibling <...>
For example: http://codepen.io/glebkema/pen/qayLYY
var myCarousel = $('#myCarousel');
var myNav = myCarousel.prev();
myNav.find('li > a').click(function() {
var newIndex = $(this).parent().index();
myCarousel.carousel( newIndex );
});
myCarousel.on('slid.bs.carousel', function () {
var newIndex = $(this).find('.carousel-inner>.active').index();
var newLI = myNav.children().eq( newIndex );
if ( !newLI.hasClass('active') ) {
myNav.find('li.active').removeClass('active');
newLI.addClass('active');
}
});
/* Make the images wide and responsive. */
.carousel-inner img {
height: auto;
width: 100%;
}
/* Count nav-pills */
.nav {
counter-reset: number;
padding: 12px 0;
}
.nav > li > a:before {
content: counter(number);
counter-increment: number;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<div class="container">
<ul class="nav nav-pills">
<li role="presentation" class="active"></li>
<li role="presentation"></li>
<li role="presentation"></li>
<li role="presentation"></li>
<li role="presentation"></li>
<li role="presentation"></li>
</ul>
<div id="myCarousel" class="carousel slide" data-ride="carousel">
<div class="carousel-inner" role="listbox">
<div class="item active">
<img src="https://via.placeholder.com/900x300/c69/fff/?text=1" alt="">
</div>
<div class="item">
<img src="https://via.placeholder.com/900x300/9c6/fff/?text=2" alt="">
</div>
<div class="item">
<img src="https://via.placeholder.com/900x300/69c/fff/?text=3" alt="">
</div>
<div class="item">
<img src="https://via.placeholder.com/900x300/c33/fff/?text=4" alt="">
</div>
<div class="item">
<img src="https://via.placeholder.com/900x300/099/fff/?text=5" alt="">
</div>
<div class="item">
<img src="https://via.placeholder.com/900x300/f93/fff/?text=6" alt="">
</div>
</div>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
I have a carousel that's the full width of the page. Now I need to make the carousel-caption the full width of the page as well with a yellow background. The background should be the full width of the page, but the actual caption text should be centered.
This is what it should look like:
This is what it looks like now:
HTML:
<!--START CAROUSEL-->
<div id="carousel-example-generic" class="carousel slide" data-ride="carousel" data-interval="false">
<!-- Wrapper for slides -->
<div class="carousel-inner" role="listbox">
<div class="item active">
<img src="../../images/LD/desktop_hero1.png" alt="...">
<div class="carousel-caption">
Text for caption 1 here.
</div>
</div>
<div class="item">
<img src="../../images/LD/desktop_hero2.png" alt="...">
<div class="carousel-caption">
Text for caption 2 here.
</div>
</div>
<div class="item">
<img src="../../images/LD/desktop_hero3.png" alt="...">
<div class="carousel-caption">
Text for caption 3 here.
</div>
</div>
</div>
<!-- Controls -->
<a class="left carousel-control" href="#carousel-example-generic" 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="#carousel-example-generic" role="button" data-slide="next">
<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
<!--END CAROUSEL-->
CSS:
<style type="text/css">
.carousel-caption {
max-width: 100%;
width:100%;
background-color: #ffb81c;
}
</style>
carousel-caption class declares the div to have an absolute positioning with its position to be 15 % from left.
So you can try to override that. Here is the css:
.carousel-caption {
max-width: 100%;
width:100%;
background-color: #ffb81c;
left: 0;
}
you only need to add text-align: center becaus actually it uses the full width already
if something is floating u can use a clearfix to solve it, check this jsfidlle
title example
<div class="carousel-caption">
<h1>
Text for caption 1 here.
</h1>
</div>
.carousel-caption h1 {
max-width: 100%;
background-color: #ffb81c;
text-align:center;
}
pd. i added the h1 tag to have a better semantic structure.