Carousel caption - css

I have this little carousel that moves on mousehover
http://jsfiddle.net/dpn3t9p6/1/
HTML
<div id ="container">
<div id="parent">
<div class="contentBlock">
<img alt="Les Bourdelles Des Garcons" src="http://www.deblasiis.com/wp-content/uploads/2016/10/MG_4194-copia-3.png">
<p class="bsubtitle11"><span>Les Bourdelles des Garcons</span></p>
</div>
<div class="contentBlock"><img alt="Religio Universalis" src="http://www.deblasiis.com/wp-content/uploads/2016/11/MG_7877-dOUBLE.jpg"></div>
<div class="contentBlock"><img alt="Isal Bed Ollen" src="http://www.deblasiis.com/wp-content/uploads/2016/11/01-N-1.jpg"></div>
</div>
</div>
<span id="panLeft" class="panner" data-scroll-modifier='-1'><</span>
<span id="panRight" class="panner" data-scroll-modifier='1'>></span>
CSS
#container {
width:600px;
overflow:hidden;
}
#parent {
width:6000px;
}
.contentBlock {
font-size:10em;
text-align:center;
line-height:400px;
height:auto;
width:auto;
margin:2px;
float:left;
}
.contentBlock img {
height:600px;
width:auto;
}
.panner {
border:1px solid black;
display:block;
position:fixed;
width:50px;
height:50px;
top:45%;
}
.active {
color:red;
}
#panLeft {
left:0px;
}
#panRight {
right:0px;
}
JS
var scrollHandle = 0,
scrollStep = 5,
parent = $("#container");
//Start the scrolling process
$(".panner").on("mouseenter", function () {
var data = $(this).data('scrollModifier'),
direction = parseInt(data, 10);
$(this).addClass('active');
startScrolling(direction, scrollStep);
});
//Kill the scrolling
$(".panner").on("mouseleave", function () {
stopScrolling();
$(this).removeClass('active');
});
//Actual handling of the scrolling
function startScrolling(modifier, step) {
if (scrollHandle === 0) {
scrollHandle = setInterval(function () {
var newOffset = parent.scrollLeft() + (scrollStep * modifier);
parent.scrollLeft(newOffset);
}, 10);
}
}
function stopScrolling() {
clearInterval(scrollHandle);
scrollHandle = 0;
}
I want a text caption over the image. I can't figure it out, in my tests (https://jsfiddle.net/g5vakqw5/2/) caption will always follow the movement of carousel and won't stay adherent to the image.
Thank you for your time and help

You just need to make the position of the contentBlock relative. See here your jsfiddle
.contentBlock {
position: relative; // <---- here is the change
font-size:10em;
text-align:center;
line-height:400px;
height:auto;
width:auto;
margin:2px;
float:left;
}
(function () {
var scrollHandle = 0,
scrollStep = 5,
parent = $("#container");
//Start the scrolling process
$(".panner").on("mouseenter", function () {
var data = $(this).data('scrollModifier'),
direction = parseInt(data, 10);
$(this).addClass('active');
startScrolling(direction, scrollStep);
});
//Kill the scrolling
$(".panner").on("mouseleave", function () {
stopScrolling();
$(this).removeClass('active');
});
//Actual handling of the scrolling
function startScrolling(modifier, step) {
if (scrollHandle === 0) {
scrollHandle = setInterval(function () {
var newOffset = parent.scrollLeft() + (scrollStep * modifier);
parent.scrollLeft(newOffset);
}, 10);
}
}
function stopScrolling() {
clearInterval(scrollHandle);
scrollHandle = 0;
}
}());
#container {
width:1980px;
overflow:hidden;
}
#parent {
width:2532px;
}
.contentBlock {
position: relative;
font-size:10em;
text-align:center;
line-height:400px;
height:auto;
width:auto;
margin:2px;
float:left;
}
.contentBlock img {
height: 850px;
width:auto;
-webkit-filter: grayscale(100%);
filter: grayscale(100%);
-webkit-transition: .3s ease-in-out;
transition: .3s ease-in-out;
}
.contentBlock:hover img {
-webkit-filter: grayscale(0);
filter: grayscale(0);}
.panner {
border:1px solid black;
display:block;
position:fixed;
width:50px;
height:50px;
top:45%;
}
.active {
color:red;
}
#panLeft {
left:0px;
}
#panRight {
right:0px;
}
.bsubtitle11 {
font-weight:300;
font-size:35px;
text-align:center;
background: rgba(0,0,0,0.5);
color: white;
cursor: pointer;
display: table;
height: 150px;
left: 0;
position: absolute;
top: 45%;
width: auto;
opacity: 1;
-webkit-transition: opacity 500ms;
-moz-transition: opacity 500ms;
-o-transition: opacity 500ms;
transition: opacity 500ms;
}
.contentBlock:hover .bsubtitle11 {
opacity: 1;
}
.bsubtitle11 span {
display: table-cell;
text-align: center;
vertical-align: middle;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id ="container">
<div id="parent">
<div class="contentBlock">
<img alt="Les Bourdelles Des Garcons" src="http://www.deblasiis.com/wp-content/uploads/2016/10/MG_4194-copia-3.png">
<p class="bsubtitle11"><span>Les Bourdelles des Garcons</span></p>
</div>
<div class="contentBlock"><img alt="Religio Universalis" src="http://www.deblasiis.com/wp-content/uploads/2016/11/MG_7877-dOUBLE.jpg"></div>
<div class="contentBlock"><img alt="Isal Bed Ollen" src="http://www.deblasiis.com/wp-content/uploads/2016/11/01-N-1.jpg"></div>
</div>
</div>
<span id="panLeft" class="panner" data-scroll-modifier='-1'><</span>
<span id="panRight" class="panner" data-scroll-modifier='1'>></span>

If you want The text to be fixed and not me with image carousel, Then create one seprate tag add your text and make it position: absolute.
Use top and left values to place it properly over the image:
CSS:
#container {
width:600px;
overflow:hidden;
position: relative:
}
#container p {
position: absolute;
top: 50px;
left: 50px;
font-size: 24px;
font-weight: bold;
}
JS FIDDLE LINK

Related

In React, is there a way to have a toggle switch, onChange or onClick, switch to either the first function (thirtyDays) or the second function (year)?

I am trying to allow the user to select what will display via a toggle switch. For example, I have two functions: thirtyDays & year. Either onChange or onClick, I would like for the user to be able to switch which function is called. Is there a way to do this? Here is my code for the ToggleButton component:
thirtyDays = (props) => {
console.log("the past 30 days of transactions");
var now = new Date();
now.setDate(now.getDate() - 30);
}
year = (props) => {
console.log("year of transactions");
var now = new Date();
now.setDate(now.getDate() - 365);
}
render() {
return (
<label className="switch">
{
<>
{" "}
<input type="checkbox" id="togBtn" />
<div type="button" className="slider round">
<span className="on">Year</span>
<span className="off">30 Days</span>
</div>
</>
}
</label>
);
}
}
Here is my css:
.switch {
position: relative;
display: inline-block;
width: 175px;
height: 50px;
}
.switch input {display:none;}
.slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: forestgreen;
-webkit-transition: .4s;
transition: .4s;
}
.slider:before {
position: absolute;
content: "";
height: 50px;
width:50px;
left: 10px;
background-color: white;
-webkit-transition: .4s;
transition: .4s;
}
input:checked + .slider {
background-color: #2ab934;
}
input:focus + .slider {
box-shadow: 0 0 1px rgb(2, 61, 2);
}
input:checked + .slider:before {
-webkit-transform: translateX(100px);
-ms-transform: translateX(100px);
transform: translateX(100px);
}
/*------ ADDED CSS ---------*/
.on
{
display: none;
}
.off, .on
{
color: white;
position: absolute;
transform: translate(-50%,-50%);
top: 50%;
left: 50%;
font-size: 10px;
font-family: Verdana, sans-serif;
font-size: 15px;
}
input:checked+ .slider .on
{display: block;}
input:checked + .slider .off
{display: none;}
/*--------- END --------*/
/* Rounded sliders */
.slider.round {
border-radius: 34px;
}
.slider.round:before {
border-radius: 50%;}
Here is my codesandbox: https://codesandbox.io/s/ancient-rgb-y62rm?file=/src/App.js
You can decide about function which you call checking state of your checkbox inside another function. Example:
const changePeriod = (e) => {
if ( console.log( e.target.checked ) ) {
year( /* your params */ )
} else {
thirtyDays( /* your params */ )
}
}
return (
<div className="App">
<input type="checkbox" onChange={ changePeriod }/>
</div>
);
You would have to maintain the toggle state in your component. Or, if you're willing to use a plugin, you could try react-switch.
Here's a working example - https://codesandbox.io/s/frosty-water-l4pr6

Toggle visibility of multiple elements sharing the same class name

I have a slider and I want it when it slides one way it hides all the elements on the page with a classname="siteContainer". When I click it again I want it to display all the elements with the classname="siteContainer"
Because there are many elements I need a loop (which I have). I have managed to make all the elements visible but been unable to make the visible again.
The elements are not contiguous so cannot be grouped into one div with one ID.
It is in codepen https://codepen.io/payling/pen/MRmvwY
and below
<script>
function setDisplay(className, displayValue) {
var items = document.getElementsByClassName(className);
for (var i=0; i < items.length; i++) {
items[i].style.display = displayValue;
}
}
function showsiteContainer() {
setDisplay("siteContainer", "none");
}
</script>
function showsiteContainer() {
var x = document.getElementById("block");
if (x.style.display === "none") {
x.style.display = "block";
} else {
x.style.display = "none";
}
}
<style>
.siteContainer {
display:flex;
width:40px;
hieght:40px;
color:black;
text-decoration:none;
font-size:13px;
padding:5px;
border-top-color: rgb(133, 130, 130);
border-top-style:dotted;
border-width: 1px;
}
/* SLIDE BUTTON*/
.switch {
position: relative;
display: inline-block;
width: 40px;
height: 20px;
}
.switch input {
opacity: 0;
width: 0;
height: 0;
}
.slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #EDEDED;
-webkit-transition: .4s;
transition: .4s;
}
.slider:before {
position: absolute;
content: "";
height: 12px;
width: 12px;
left: 4px;
bottom: 4px;
background-color: white;
-webkit-transition: .4s;
transition: .4s;
}
input:checked + .slider {
background-color: #1C77C3;
}
input:focus + .slider {
box-shadow: 0 0 1px #2196F3;
}
input:checked + .slider:before {
-webkit-transform: translateX(18px);
-ms-transform: translateX(18px);
transform: translateX(18px);
}
/* Rounded sliders */
.slider.round {
border-radius: 24px;
}
.slider.round:before {
border-radius: 50%;
}
</style>
<body>
<div>
<span>DETAILS</span>
<label class="switch">
<input type="checkbox" onclick="showsiteContainer()" >
<span class="slider round"></span>
</label>
</div>
<div>
<div class="siteContainer">an element</div>
<div class="siteContainer">2nd element</div>
</div>
<div class="siteContainer">3rd element</div>
<div class="siteContainer">4th element</div>
</div>
</body>
Have a look at your example with a slight modification, I rewrote your function with :
function showsiteContainer() {
var elements = document.getElementsByClassName("siteContainer");
Array.prototype.forEach.call(elements, function(el) {
if (el.style.display === "none") {
el.style.display = "block";
} else {
el.style.display = "none";
}
});
}
https://codepen.io/Xolkys/pen/rbmzXz

Add SlideDown effect on modal close CSS

I have this style for my modal and I wonder where and how do I reverse slideUp effect on modal close.
var modal = document.getElementById('myModal');
var btn = document.getElementById("myBtn");
var span = document.getElementsByClassName("close")[0];
btn.onclick = function() {
modal.style.display = "block";
}
span.onclick = function() {
modal.style.display = "none";
}
window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = "none";
}
}
.modal {
display: none;
position: fixed;
overflow: hidden;
left: 0;
bottom: 0;
width: 100%;
height: auto;
background-color: black;
color: white;
-webkit-animation: slideIn 0.4s;
animation: slideIn 0.4s;
}
#-webkit-keyframes slideIn {
from {bottom: -300px; opacity: 0}
to {bottom: 0; opacity: 1}
}
#keyframes slideIn {
from {bottom: -300px; opacity: 0}
to {bottom: 0; opacity: 1}
}
.close {
color: white;
float: right;
font-size: 28px;
font-weight: bold;
}
<div id="myModal" class="modal">
<span class="close">×</span>
<p>Some content here</p>
</div>
Basically I want to modal closing same way it is showing (same animation on modal open and modal close, pure CSS only), can someone help me with that?
I would use a transition that is applied when you add and remove a class:
.modal {
position: fixed;
overflow: hidden;
left: 0;
bottom: 0;
width: 100%;
height: auto;
background-color: black;
color: white;
transition: opacity 0.4s, bottom 0.4s; /* animate these properties */
opacity: 1; /* open state is shown */
}
.modal.closed {
opacity: 0; /* close state is hidden and off screen */
bottom: -300px;
}
.close {
color: white;
float: right;
font-size: 28px;
font-weight: bold;
}
<div id="myModal" class="modal closed">
<span class="close">×</span>
<p>Some content here</p>
</div>
<div id="myBtn">click me</div>
<script>
var modal = document.getElementById('myModal');
var btn = document.getElementById("myBtn");
var span = document.getElementsByClassName("close")[0];
btn.onclick = function(e) {
e.stopPropagation(); /* stop event bubbling up to window */
modal.classList.remove("closed");
}
span.onclick = function() {
modal.classList.add("closed");
}
window.onclick = function(event) {
if (event.target != modal) {
modal.classList.add("closed");
}
}
</script>

Resize css spinner

I'm using a css3 spinner from http://cssload.net/ I want to know how the scale it up or down using px em or % by changing the height and width on #floatingBarsG. If I set the size 10px higher and 10px wider the icon goes out of shape. Any suggestions ?
Here is a working js fiddle example http://jsfiddle.net/PWLzb/8/
This is the html
<div id="floatingBarsG" style="">
<div id="rotateG_01" class="blockG"></div>
<div id="rotateG_02" class="blockG"></div>
<div id="rotateG_03" class="blockG"></div>
<div id="rotateG_04" class="blockG"></div>
<div id="rotateG_05" class="blockG"></div>
<div id="rotateG_06" class="blockG"></div>
<div id="rotateG_07" class="blockG"></div>
<div id="rotateG_08" class="blockG"></div>
</div>
and css
#floatingBarsG {
position:relative;
width:62px;
height:77px
}
.blockG {
position:absolute;
background-color:#FFFFFF;
width:10px;
height:24px;
-webkit-border-radius:8px 8px 0 0;
-webkit-transform:scale(0.4);
-webkit-animation-name:fadeG;
-webkit-animation-duration:0.5599999999999999s;
-webkit-animation-iteration-count:infinite;
-webkit-animation-direction:linear;
border-radius:8px 8px 0 0;
transform:scale(0.4);
animation-name:fadeG;
animation-duration:0.5599999999999999s;
animation-iteration-count:infinite;
animation-direction:linear;
}
#rotateG_01 {
left:0;
top:28px;
-webkit-animation-delay:0.20999999999999996s;
-webkit-transform:rotate(-90deg);
animation-delay:0.20999999999999996s;
transform:rotate(-90deg);
}
#rotateG_02 {
left:8px;
top:10px;
-webkit-animation-delay:0.27999999999999997s;
-webkit-transform:rotate(-45deg);
animation-delay:0.27999999999999997s;
transform:rotate(-45deg);
}
#rotateG_03 {
left:26px;
top:3px;
-webkit-animation-delay:0.35s;
-webkit-transform:rotate(0deg);
animation-delay:0.35s;
transform:rotate(0deg);
}
#rotateG_04 {
right:8px;
top:10px;
-webkit-animation-delay:0.41999999999999993s;
-webkit-transform:rotate(45deg);
animation-delay:0.41999999999999993s;
transform:rotate(45deg);
}
#rotateG_05 {
right:0;
top:28px;
-webkit-animation-delay:0.48999999999999994s;
-webkit-transform:rotate(90deg);
animation-delay:0.48999999999999994s;
transform:rotate(90deg);
}
#rotateG_06 {
right:8px;
bottom:7px;
-webkit-animation-delay:0.5599999999999999s;
-webkit-transform:rotate(135deg);
animation-delay:0.5599999999999999s;
transform:rotate(135deg);
}
#rotateG_07 {
bottom:0;
left:26px;
-webkit-animation-delay:0.63s;
-webkit-transform:rotate(180deg);
animation-delay:0.63s;
transform:rotate(180deg);
}
#rotateG_08 {
left:8px;
bottom:7px;
-webkit-animation-delay:0.7s;
-webkit-transform:rotate(-135deg);
animation-delay:0.7s;
transform:rotate(-135deg);
}
#-webkit-keyframes fadeG {
0% {
background-color:#000000
}
100% {
background-color:#FFFFFF
}
}
#keyframes fadeG {
0% {
background-color:#000000
}
100% {
background-color:#FFFFFF
}
}
This can be done very easily via CSS scale transforms:
#floatingBarsG {
-webkit-transform:scale(2);
-webkit-transform-origin:top left;
-moz-transform:scale(2);
-moz-transform-origin:top left;
-ms-transform:scale(2);
-ms-transform-origin:top left;
-o-transform:scale(2);
-o-transform-origin:top left;
transform:scale(2);
transform-origin:top left;
}
Demo.
Edit from 8 years after posting this answer: Nowadays, all of these prefixes are no longer necessary, so simply using the following would suffice:
#floatingBarsG {
transform:scale(2);
transform-origin:top left;
}

Mootools 1.4.3 Background Fade Effect

So I have code to swap the background, the problem I am having is incorporating the fade effect into it. I have messed with it for a while now and I am just getting frustrated. So the code is there, see how you can hack this to work.
Mootools 1.4.3
.socialIconsFB {
float: right;
display: block;
margin: -20px 3px;
width: 48px;
height: 57px;
background-image: url(XXXXXX/social_icons/facebook.png);
}
<div class="socialIconsFB"></div>
$$('.socialIconsFB').each(function(socialIconsFB) {
socialIconsFB.addEvent('mouseover', function() {
this.tween("background-image", "url(XXXXXX/social_icons/facebook.png)", "url(XXXXXX/social_icons/facebook_highlight.png)");
});
socialIconsFB.addEvent('mouseout', function() {
this.tween("background-image", "url(XXXXXX/social_icons/facebook.png)");
});
});
I think that "tween" effects not work with "background-image" but work with "background-color"
I would try in this way:
HTML:
<div class="socialIconsFB">
<span></span>
</div>
CSS:
.socialIconsFB {
float: right;
display: block;
margin: -20px 3px;
width: 48px;
height: 57px;
background-image: url(XXXXXX/social_icons/facebook.png);
}
.socialIconsFB span{
margin:0; padding:0;
opacity:0; filter:alpha(opacity=0);
width:100%;
height:100%;
background-image: url(XXXXXX/social_icons/facebook_highlight.png);
}
JAVASCRIPT:
$$('.socialIconsFB').each(function(socialIconsFB) {
socialIconsFB.addEvents({
'mouseenter': function(){
this.getChildren('span').tween("opacity", 1);
//it could be: this.getChildren('span')[0]
},
'mouseleave': function(){
this.getChildren('span').tween("opacity", 0);
//it could be: this.getChildren('span')[0]
}
});
});

Resources