I'm trying to make an image slideshow that has a transition effect like seen here. I unfortunately only have this gif to go by and I have not been able to locate live web example. The slideshow should show 3 images at a time, then slide to the next 3, and so on. I started with using the slick slider to do most of the slideshow work for me (this is not a requirement). But I'm having difficulty recreating a transition that looks like the effect in the sample. I tried animating padding between the images but that causes the images to change size and causing the images to go off center. Using box-sizing: border-box did not help in this case. Any help on how to create this transition would be greatly appreciated. Here's my code:
$(document).ready(function(){
$('.slider').slick({
infinite: true,
arrows: true,
slidesToShow: 3,
slidesToScroll: 3,
speed: 500
});
});
.wrapper{
position: relative;
box-sizing: border-box;
}
.slick-slide img{
width:100%;
box-sizing:border-box;
}
.slick-slide{
padding: 0;
box-sizing: border-box;
}
.slick-active{
animation: slidetransition;
animation-duration: 3s;
}
#keyframes slidetransition {
0% {
padding: 0px;
}
50% {
padding: 0px 25px;
}
100% {
padding:0;
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.8.1/slick.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.8.1/slick.min.js"></script>
<div class="wrapper">
<div class="slider">
<div class="group1">
<img src="http://placehold.it/350x150/292929/dd0909&text=Slide_1">
</div>
<div class="group1">
<img src="http://placehold.it/350x150/292929/dd6809&text=Slide_2">
</div>
<div class="group1">
<img src="http://placehold.it/350x150/292929/fdff3b&text=Slide_3">
</div>
<div class="group2">
<img src="http://placehold.it/350x150/292929/3bff3b&text=Slide_4">
</div>
<div class="group2">
<img src="http://placehold.it/350x150/292929/5d87ff&text=Slide_5">
</div>
<div class="group2">
<img src="http://placehold.it/350x150/292929/ab8df8&text=Slide_6">
</div>
</div>
</div>
If you can group your items in groups of 3, this solution can work for you.
I am setting different delays to achieve the effect of the items moving separately and the grouping again
var page = 1;
window.onload = function() {
setInterval(changePage, 4000);
}
function changePage() {
var previous = document.querySelector(".previous");
if (previous) {
previous.classList.remove("previous");
}
var active = document.querySelector(".active");
active.classList.remove("active");
active.classList.add("previous");
page++;
if (page > 3) {
page = 1;
}
var id = "page" + page;
var newActive = document.getElementById(id);
newActive.classList.add("active");
}
.carousel {
height: 150px;
width: 500px;
position: relative;
}
.page {
width: 100%;
height: 100%;
display: flex;
position: absolute;
overflow: hidden;
}
.elem {
height: 98%;
width: 33%;
font-size: 100px;
border: solid 1px black;
transition: transform 1s;
transform: translateX(300%);
opacity: 0;
}
.active .elem {
transform: translateX(0%);
opacity: 1;
}
.previous .elem {
transform: translateX(-300%);
opacity: 1;
}
.elem:nth-child(1) {
background-color: tomato;
transition-delay: 0s;
}
.elem:nth-child(2) {
background-color: yellow;
transition-delay: 0.1s;
}
.elem:nth-child(3) {
background-color: lightblue;
transition-delay: 0.2s;
}
.active .elem:nth-child(1) {
transition-delay: 0.3s;
}
.active .elem:nth-child(2) {
transition-delay: 0.4s;
}
.active .elem:nth-child(3) {
transition-delay: 0.5s;
}
<div class="carousel">
<div class="page active" id="page1">
<div class="elem">1</div>
<div class="elem">1</div>
<div class="elem">1</div>
</div>
<div class="page" id="page2">
<div class="elem">2</div>
<div class="elem">2</div>
<div class="elem">2</div>
</div>
<div class="page" id="page3">
<div class="elem">3</div>
<div class="elem">3</div>
<div class="elem">3</div>
</div>
</div>
Here another snippet, working with nbuttons, and responsive
var page = 1;
var numPages = 4;
function forward() {
changePage(1);
}
function back() {
changePage(-1);
}
function changePage (inc) {
var ele = document.querySelector(".carousel");
if (inc > 0) {
ele.className = "carousel forward";
} else {
ele.className = "carousel back";
}
page += inc;
if (page > numPages) {
page = 1;
}
if (page < 1) {
page = numPages;
}
var id = page - 3;
if (id < 0) {
id += numPages;
}
document.getElementById("page" + (id % numPages)).className = "page";
id ++;
document.getElementById("page" + (id % numPages)).className = "page left";
id ++;
document.getElementById("page" + id % numPages).className = "page active";
id ++;
document.getElementById("page" + id % numPages).className = "page right";
id ++;
document.getElementById("page" + id % numPages).className = "page";
}
.carousel {
height: 200px;
width: 98%;
border: solid 3px black;
position: relative;
margin-left: 1%;
}
.page {
eft: 300px;
width: 100%;
height: 100%;
display: flex;
flex-direction: row;
position: absolute;
overflow: hidden;
}
.page:nth-child(2) {
op: 100px;
}
.page:nth-child(3) {
op: 200px;
}
.elem {
height: 100%;
width: 33.33%;
font-size: 100px;
transition: transform 1s;
transform: translateX(300%);
z-index: 1;
opacity: 0;
}
.active .elem {
transform: translateX(0%);
z-index: 2;
opacity: 1;
}
.left .elem {
transform: translateX(-300%);
}
.forward .left .elem {
z-index: 2;
opacity: 1;
}
.right .elem {
transform: translateX(300%);
}
.back .right .elem {
z-index: 2;
opacity: 1;
}
.elem:nth-child(1) {
background-color: tomato;
}
.elem:nth-child(2) {
background-color: yellow;
}
.elem:nth-child(3) {
background-color: lightblue;;
}
.back .right .elem:nth-child(3) {
transition-delay: 0s;
}
.back .right .elem:nth-child(2) {
transition-delay: 0.1s;
}
.back .right .elem:nth-child(1) {
transition-delay: 0.2s;
}
.back .active .elem:nth-child(3) {
transition-delay: 0.3s;
}
.back .active .elem:nth-child(2) {
transition-delay: 0.4s;
}
.back .active .elem:nth-child(1) {
transition-delay: 0.5s;
}
.forward .left .elem:nth-child(1) {
transition-delay: 0s;
}
.forward .left .elem:nth-child(2) {
transition-delay: 0.1s;
}
.forward .left .elem:nth-child(3) {
transition-delay: 0.2s;
}
.forward .active .elem:nth-child(1) {
transition-delay: 0.3s;
}
.forward .active .elem:nth-child(2) {
transition-delay: 0.4s;
}
.forward .active .elem:nth-child(3) {
transition-delay: 0.5s;
}
button {
font-size: 20px;
margin: 20px;
}
<div class="carousel forward">
<div class="page active" id="page0">
<div class="elem">1</div>
<div class="elem">1</div>
<div class="elem">1</div>
</div>
<div class="page right" id="page1">
<div class="elem">2</div>
<div class="elem">2</div>
<div class="elem">2</div>
</div>
<div class="page" id="page2">
<div class="elem">3</div>
<div class="elem">3</div>
<div class="elem">3</div>
</div>
<div class="page left" id="page3">
<div class="elem">4</div>
<div class="elem">4</div>
<div class="elem">4</div>
</div>
</div>
<button onclick="back()">back</button>
<button onclick="forward()">forward</button>
For performance, a simple transform:translate with pure CSS is much better. If you just need 2 groups of 3 images, the following will do
/*just toggles the "toggle" class on the "slider" element
/* when clicking the toggle button*/
document.getElementById("toggle").addEventListener("click", function(){
document.getElementById("slider").classList.toggle("toggle");
});
.wrapper{
/*hides the 3 overflowing imgs, preventing scrollbars*/
width:100%; overflow:hidden;
}
.slider{
/*classic inline-block whitespace hack*/
font-size:0;
/* so the 2 "groups" are side by side */
width:200%;
/*sets the transition between groups with some delay*/
transition: transform 1.2s;
}
.slider img{
/*sizes the imgs acording to the fixed quantity*/
width:calc(100% / 6);
/*set the transition for the imgs separation*/
transition: transform 1s;
/*sets the default value for transform*/
transform:translateX(0);
}
/*when "toggle" is not active, last images move to the right*/
.slider img:nth-child(4){transform:translateX(40px);}
.slider img:nth-child(5){transform:translateX(80px);}
.slider img:nth-child(6){transform:translateX(120px);}
/*when active, the slide moves 50% left so the second group shows*/
.slider.toggle{transform:translateX(-50%)}
/*when active, first two images move displaces to the left*/
.slider.toggle img:nth-child(1){transform:translateX(-80px);}
.slider.toggle img:nth-child(2){transform:translateX(-40px);}
/*when active, last two images reset to regular position*/
.slider.toggle img:nth-child(4){transform:translateX(0);}
.slider.toggle img:nth-child(5){transform:translateX(0);}
.slider.toggle img:nth-child(6){transform:translateX(0);}
<div class="wrapper">
<div class="slider" id="slider">
<img src="http://placehold.it/350x150/292929/dd0909&text=Slide_1">
<img src="http://placehold.it/350x150/292929/dd6809&text=Slide_2">
<img src="http://placehold.it/350x150/292929/fdff3b&text=Slide_3">
<img src="http://placehold.it/350x150/292929/3bff3b&text=Slide_4">
<img src="http://placehold.it/350x150/292929/5d87ff&text=Slide_5">
<img src="http://placehold.it/350x150/292929/ab8df8&text=Slide_6">
</div>
</div>
<button id="toggle">toggle slides</button>
Feel free to use javascript to automatically switch the groups, it's just a matter of toggling the "toggle" class list.
I've used a button toggle just for testing purposes.
Related
I've got the following code. When the user hovers over the div, it should drop and stay that way until the user has hovered off of the div. When on the div, even if you move your mouse a bit, the hover action keeps firing.
html
<div class="whitelabelfeatures">
<div class="box1 requirements responsibilities">
<div class="responsibilitiesbox">
<div class="responsibility">
<div class="section1">
Pricing
</div>
<div class="section1a">
Pricing test
</div>
</div>
</div>
</div>
</div>
css
.box1.requirements.responsibilities {
height: 300px;
overflow: hidden;
}
.responsibility .section1 {
background-color: #c2bbb1;
height: 300px;
color: white;
font-weight: 700;
position: relative;
z-index: 2;
transition: all .3s ease;
}
.responsibility .section1:hover {
transform: translateY(300px);
}
.responsibility .section1a {
position: absolute;
z-index: 1;
top: 0;
}
codepen
https://codepen.io/jasonhoward64/pen/YzKNxVN
Thanks!
You can use javascript here. Please see below code.
var targetDiv = document.getElementsByClassName("section1")[0];
targetDiv.addEventListener('mouseenter', function(){
targetDiv.classList.add('section1mouseover');
});
var testDiv = document.getElementsByClassName("section1a")[0];
testDiv.addEventListener('mouseenter', function(){
targetDiv.classList.remove('section1mouseover');
});
.box1.requirements.responsibilities {
height: 300px;
overflow: hidden;
}
.responsibility .section1 {
background-color: #c2bbb1;
height: 300px;
color: white;
font-weight: 700;
position: relative;
z-index: 2;
transition: all .3s ease;
}
.section1mouseover {
transform: translateY(300px);
}
.responsibility .section1a {
position: absolute;
z-index: 1;
top: 0;
}
<div class="whitelabelfeatures">
<div class="box1 requirements responsibilities">
<div class="responsibilitiesbox">
<div class="responsibility">
<div class="section1">
Pricing
</div>
<div class="section1a">
Pricing test
</div>
</div>
</div>
</div>
</div>
The problem is that your :hover needs to be actuated higher in the DOM. With your current code, when you hover over the .section1 element, once the CSS transform takes place and translates the .section1 element vertically, the cursor is both "off" and "over" the transforming element, which causes the :hover to trigger on and off in response.
So in your codepen, on line 17, change your hover to the parent element and it should work.
Instead of:
.responsibility .section1:hover, try .responsibility:hover .section1
I find it quite hard to explain, but I have made a demo here:
http://plnkr.co/edit/X0X4RAFjnUX7LzBL1R6p?p=preview
Basically I have 2 columns that are side-by-side. When the page gets smaller, the columns go under each other. One of the columns has a slider plugin where the image change. The wrapper has a relative position so it changes size. The images inside use an absolute position for the slider to work.
Under those images I want 3 separate images that always stay under. Unfortunately, I can only get them to appear either on the main image, or under the layer (not positioned below).
Here's the entire code:
var timer = setInterval(nextImage, 4000);
var curImage = 0;
var numImages = 3;
function nextImage() {
var e;
// remove showMe class from current image
e = document.getElementById("slideimg" + curImage);
removeClass(e, "showMe");
// compute next image
curImage++;
if (curImage > numImages - 1) {
curImage = 0;
}
// add showMe class to next image
e = document.getElementById("slideimg" + curImage);
addClass(e, "showMe");
}
function addClass(elem, name) {
var c = elem.className;
if (c) c += " "; // if not blank, add a space separator
c += name;
elem.className = c;
}
function removeClass(elem, name) {
var c = elem.className;
elem.className = c.replace(name, "").replace(/ /g, " ").replace(/^ | $/g, ""); // remove name and extra blanks
}
body,
html {
height: 100%
}
body {
min-height: 100%;
background-position: center;
background-size: cover;
font-family: 'Lato', sans-serif;
font-weight: 400;
margin: 0;
}
#content {
max-width: 1750px;
margin-left: auto;
margin-right: auto;
}
* {
box-sizing: border-box;
}
/* Create two equal columns that floats next to each other */
.column {
float: left;
width: 50%;
padding-top: 20px;
padding-bottom: 20px;
padding-left: 30px;
padding-right: 30px;
}
/* Clear floats after the columns */
.row:after {
content: "";
display: table;
clear: both;
}
/* Responsive layout - makes the two columns stack on top of each other instead of next to each other */
#media screen and (max-width: 900px) {
.column {
width: 100%;
}
}
.homepage-main-img-wrapper {
position: relative;
right: 0;
left: 0;
margin: auto;
height: 100%;
}
.homepage-main-img {
width: 100%;
border: 2px solid #194d98;
outline: 2px solid #0c7d5f;
}
.slide {
border: none;
opacity: 0;
position: absolute;
top: 0;
left: 0;
-webkit-transition: opacity 2s linear;
-moz-transition: opacity 2s linear;
-o-transition: opacity 2s linear;
transition: opacity 2s linear;
}
.showMe {
opacity: 1;
}
<html lang="et" xml:lang="et">
<body>
<div id="container">
<div id="content">
<div class="row">
<div class="column" style="background-color:#aaa;">
<div>stuff</div>
</div>
<div class="column container2">
<div class="homepage-main-img-wrapper">
<img id="slideimg0" class="slide homepage-main-img showMe" src="https://i.imgur.com/n3oGBvR.jpg">
<img id="slideimg1" class="slide homepage-main-img" src="https://i.imgur.com/Ak7Ykl8.jpg">
<img id="slideimg2" class="slide homepage-main-img" src="https://i.imgur.com/tSmA8zP.jpg">
</div>
<div id="test" style="
position: relative;
">
<div id="instagram-feed" class="instagram_feed">
<div class="instagram_gallery">
<img src="https://i.imgur.com/aoaWgFY.jpg" style="margin:0.5% 0.5%;width:32.333333333333336%;float:left;">
<img src="https://i.imgur.com/41i7fue.jpg" style="margin:0.5% 0.5%;width:32.333333333333336%;float:left;">
<img src="https://i.imgur.com/ITSAyjN.jpg" style="margin:0.5% 0.5%;width:32.333333333333336%;float:left;">
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
Since the height of the images change when the browser is resized, you can take an existing image or transparent image with the same "homepage-main-img" class so that the scale is the same on browser resize.
I also removed the position:relative from your id test div.
Change your HTML to be the following in the HTML block. JS and CSS remains untouched. Just added for the snippit to work.
var timer = setInterval(nextImage, 4000);
var curImage = 0;
var numImages = 3;
function nextImage() {
var e;
// remove showMe class from current image
e = document.getElementById("slideimg" + curImage);
removeClass(e, "showMe");
// compute next image
curImage++;
if (curImage > numImages - 1) {
curImage = 0;
}
// add showMe class to next image
e = document.getElementById("slideimg" + curImage);
addClass(e, "showMe");
}
function addClass(elem, name) {
var c = elem.className;
if (c) c += " "; // if not blank, add a space separator
c += name;
elem.className = c;
}
function removeClass(elem, name) {
var c = elem.className;
elem.className = c.replace(name, "").replace(/ /g, " ").replace(/^ | $/g, ""); // remove name and extra blanks
}
body,
html {
height: 100%
}
body {
min-height: 100%;
background-position: center;
background-size: cover;
font-family: 'Lato', sans-serif;
font-weight: 400;
margin: 0;
}
#content {
max-width: 1750px;
margin-left: auto;
margin-right: auto;
}
* {
box-sizing: border-box;
}
/* Create two equal columns that floats next to each other */
.column {
float: left;
width: 50%;
padding-top: 20px;
padding-bottom: 20px;
padding-left: 30px;
padding-right: 30px;
}
/* Clear floats after the columns */
.row:after {
content: "";
display: table;
clear: both;
}
/* Responsive layout - makes the two columns stack on top of each other instead of next to each other */
#media screen and (max-width: 900px) {
.column {
width: 100%;
}
}
.homepage-main-img-wrapper {
position: relative;
right: 0;
left: 0;
margin: auto;
height: 100%;
}
.homepage-main-img {
width: 100%;
border: 2px solid #194d98;
outline: 2px solid #0c7d5f;
}
.slide {
border: none;
opacity: 0;
position: absolute;
top: 0;
left: 0;
-webkit-transition: opacity 2s linear;
-moz-transition: opacity 2s linear;
-o-transition: opacity 2s linear;
transition: opacity 2s linear;
}
.showMe {
opacity: 1;
}
<div id="container">
<div id="content">
<div class="row">
<div class="column" style="background-color:#aaa;">
<div>stuff</div>
</div>
<div class="column container2">
<div class="homepage-main-img-wrapper">
<img id="slideimg0" class="slide homepage-main-img showMe" src="https://i.imgur.com/n3oGBvR.jpg">
<img id="slideimg1" class="slide homepage-main-img" src="https://i.imgur.com/Ak7Ykl8.jpg">
<img id="slideimg2" class="slide homepage-main-img" src="https://i.imgur.com/tSmA8zP.jpg">
</div>
<div id="test"><img id="fakeslide" class="homepage-main-img" src="https://i.imgur.com/n3oGBvR.jpg">
<div id="instagram-feed" class="instagram_feed">
<div class="instagram_gallery">
<img src="https://i.imgur.com/aoaWgFY.jpg" style="margin:0.5% 0.5%;width:32.333333333333336%;float:left;">
<img src="https://i.imgur.com/41i7fue.jpg" style="margin:0.5% 0.5%;width:32.333333333333336%;float:left;">
<img src="https://i.imgur.com/ITSAyjN.jpg" style="margin:0.5% 0.5%;width:32.333333333333336%;float:left;">
</div>
</div>
</div>
</div>
</div>
</div>
</div>
The following code is supposed to produce a smooth scrolling effect to page transition when the appropriate link is clicked.
It is not working as intended.
The page changes as designed, but the smooth scrolling transition effect is not there. I have researched a code which does that but when applied to the project is does not work at all in any browser. I could not find out why. Any help is appreciated.
/* Styling of the Layers */
.WrapperContainer {
z-index: 0;
width: 100%;
}
.SupportLayerHome {
background-color: darkorange;
left: 0;
}
.SupportLayerSignUp {
background-color: grey;
left: 500%;
}
.SupportLayerForums {
background-color: red;
left: 100%;
}
.SupportLayerArcaneum {
background-color: blue;
left: 300%;
}
.SupportLayerBuilds {
background-color: green;
left: 200%;
}
.SupportLayerOther {
background-color: black;
left: 400%;
}
/* General styling */
nav {
background-color: #FFF;
position: fixed;
width: 100%;
height: 20px;
z-index: 1;
}
/* Common Styles */
.BaseLayers {
position: absolute;
height: 100%;
width: 100%;
color: #FFF;
-webkit-transition: left 2s ease;
-o-transition: left 2s ease;
-moz-transition: left 2s ease;
transition: left 2s ease;
}
.BaseLayers i {
position: absolute;
top: 100px;
}
a[ id="callForums"]:target~#siteContainer section.BaseLayers {
left: 0;
}
a[ id="callHome"]:target~#siteContainer section.BaseLayers {
left: 0;
}
a[ id="callBuilds"]:target~#siteContainer section.BaseLayers {
left: 0;
}
a[ id="callSignUp"]:target~#siteContainer section.BaseLayers {
left: 0;
}
a[ id="callArcaneum"]:target~#siteContainer section.BaseLayers {
left: 0;
}
a[ id="callOther"]:target~#siteContainer section.BaseLayers {
left: 0;
}
<div class="WrapperContainer" id="siteContainer">
<nav class="navbar nav-justified" id="Navigation">
Home
Forums
Builds
Arcaneum
Other
Sign-up
</nav>
<section class="SupportLayerHome BaseLayers" id="HomePage">
<i>...</i>
</section>
<section class="SupportLayerSignUp BaseLayers" id="SignUpPage">
<i>...</i>
</section>
<section class="SupportLayerForums BaseLayers" id="ForumsPage">
<i>...</i>
</section>
<section class="SupportLayerBuilds BaseLayers" id="BuildsPage">
<i>...</i>
</section>
<section class="SupportLayerArcaneum BaseLayers" id="ArcaneumPage">
<i>...</i>
</section>
<section class="SupportLayerOther BaseLayers" id="OtherPage">
<i>...</i>
</section>
</div>
EDIT:
After some weeks and research I have found out why it is not working. The answer is to link to an element "on the same page" and then instruct that element to perform the animation like it is represented here:
html,
body {
height: 100%;
width: 100%;
overflow: hidden;
}
/* Styling of the Layers */
.WrapperContainer {
height: 100%;
width: 100%;
overflow: hidden;
}
.Page1 {
background-color: darkblue;
color: #FFF;
}
.Page2 {
background-color: darkorange;
left: 100%;
-webkit-transition: left 0.5s linear;
-moz-transition: left 0.5s linear;
-o-transition: left 0.5s linear;
transition: left 0.5s linear;
}
.Page3 {
background-color: darkgreen;
left: 100%;
-webkit-transition: left 0.5s linear;
-moz-transition: left 0.5s linear;
-o-transition: left 0.5s linear;
transition: left 0.5s linear;
}
/* General Styling */
.NavigationLayer {
height: 5%;
border-bottom: 2px solid azure;
}
nav {
position: fixed;
z-index: 10;
width: 100%;
}
a[id="Page1"],
a[id="Page2"],
a[id="Page3"] {
display: none;
}
/* Common Styles */
.BaseLayers {
width: 100%;
height: 100%;
position: absolute;
padding-top: 2.5%;
}
a[id="Page1"]:target~main>section#PageOne,
a[id="Page2"]:target~main>section#PageTwo,
a[id="Page3"]:target~main>section#PageThree {
left: 0;
}
a {
color: white;
}
a:hover {
color: teal;
}
<!-- Hidden Content -->
<a id="Page1"></a>
<a id="Page2"></a>
<a id="Page3"></a>
<!--
End Hidden Content
Start NavBar
-->
<nav class="NavigationLayer" id="Navigation">
Page One
Page Two
Page Three
</nav>
<main class="WrapperContainer" id="siteContainer">
<section class="Page1 BaseLayers" id="PageOne">
<i>Page 1</i>
</section>
<section class="Page2 BaseLayers" id="PageTwo">
<i>Page 2</i>
</section>
<section class="Page3 BaseLayers" id="PageThree">
<i>Page 3</i>
</section>
There is no animation because your :target selectors aren't working. Instead, when clicking on the link you are being navigated to the position of the element, which is the normal browser behavior when clicking an internal link, which probably had you thinking that it was working without the animation. If you go back to your snippit and pay close attention to x-axis scrollbar, you should notice it moving rather than the element.
It seems like you're trying to use it to retrieve the target of a given anchor tag, however this pseudo-class is used when the element is the current target, so instead we can simply apply :target to the .nav-link elements to select them when they are the target.
I've replaced your target selectors with this rule:
.nav-link:target { left: 0; }
Note, however, that the window still attempts to adjust the view to the original location of the element, meaning the result is a little disorienting.
/* Styling of the Layers */
.WrapperContainer {
z-index: 0;
width: 100%;
}
.SupportLayerHome {
background-color: darkorange;
left: 0;
}
.SupportLayerSignUp {
background-color: grey;
left: 500%;
}
.SupportLayerForums {
background-color: red;
left: 100%;
}
.SupportLayerArcaneum {
background-color: blue;
left: 300%;
}
.SupportLayerBuilds {
background-color: green;
left: 200%;
}
.SupportLayerOther {
background-color: black;
left: 400%;
}
/* General styling */
nav {
background-color: #FFF;
position: fixed;
width: 100%;
height: 20px;
z-index: 1;
}
/* Common Styles */
.BaseLayers {
position: absolute;
height: 100%;
width: 100%;
color: #FFF;
-webkit-transition: left 2s ease;
-o-transition: left 2s ease;
-moz-transition: left 2s ease;
transition: left 2s ease;
}
.BaseLayers i {
position: absolute;
top: 100px;
}
:target { left: 0; }
<div class="WrapperContainer" id="siteContainer">
<nav class="navbar nav-justified" id="Navigation">
Home
Forums
Builds
Arcaneum
Other
Sign-up
</nav>
<section class="SupportLayerHome BaseLayers" id="HomePage">
<i>...</i>
</section>
<section class="SupportLayerSignUp BaseLayers" id="SignUpPage">
<i>...</i>
</section>
<section class="SupportLayerForums BaseLayers" id="ForumsPage">
<i>...</i>
</section>
<section class="SupportLayerBuilds BaseLayers" id="BuildsPage">
<i>...</i>
</section>
<section class="SupportLayerArcaneum BaseLayers" id="ArcaneumPage">
<i>...</i>
</section>
<section class="SupportLayerOther BaseLayers" id="OtherPage">
<i>...</i>
</section>
</div>
This slideshow technique is pretty close to what you are trying to achieve here but uses a small amount of jQuery to trigger the transitions.
http://css3.bradshawenterprises.com/sliding/
I am using this fork code to display text on mouseover of an image.
http://codepen.io/anon/pen/hxqoe
HTML
<img src="http://placekitten.com/150" alt="some text" />
<img src="http://placekitten.com/150" alt="more text" />
<img src="http://placekitten.com/150" alt="third text" />
<div id="text"></div>
CSS
div {
display: none;
position: absolute;
}
img:hover + div {
display: block;
}
JQUERY
$('img').hover(function() {
$('div').html($(this).attr('alt')).fadeIn(200);
}, function() {
$('div').html('');
});
I am looking for the div text to be displayed inside each image instead of a stationary div.
Any ideas?
You actually don't need jQuery for this. It can easily be achieved with pure CSS.
In this example, I use the :after pseudo element to add the content from the alt attribute of the parent div. You can add whatever styling you want..
jsFiddle here - Updated to include a fade
HTML - pretty simple
<div alt="...">
<img src="..."/>
</div>
CSS
div {
position: relative;
display: inline-block;
}
div:after {
content: attr(alt);
height: 100%;
background: rgba(0, 0, 0, .5);
border: 10px solid red;
position: absolute;
top: 0px;
left: 0px;
display: inline-block;
box-sizing: border-box;
text-align: center;
color: white;
padding: 12px;
font-size: 20px;
opacity: 0;
transition: 1s all;
-webkit-transition: 1s all;
-moz-transition: 1s all;
}
div:hover:after {
opacity: 1;
}
Change your javascript to this:
$('img').hover(function() {
$('div').html($(this).attr('alt')).fadeIn(200);
$('div').css('left',$(this).offset().left + 'px');
$('div').css('top',$(this).offset().top + $(this).height() - 20 + 'px');
}, function() {
$('div').html('');
});
And that should do the trick.
I would wrap your images in some kind of wrapper and then use CSS for the hover effect (DEMO).
HTML:
<div class="img-wrapper">
<img src="http://placekitten.com/150" alt="some text 1" />
<div class="img-desc">some text 1</div>
</div>
CSS:
.img-wrapper {
position: relative;
display: inline;
}
.img-desc {
display: none;
position: absolute;
bottom: 0px;
left: 0px;
width: 100%;
background: #FFF;
opacity: 0.6;
padding: 5px;
}
.img-wrapper:hover .img-desc{
display: block;
}
I added an alternative solution with additional css transition to the demo.
To get a transition just control the visibility with opacity:
.img-desc {
/*...*/
opacity: 0;
/*...*/
}
.img-wrapper:hover .img-desc{
opacity: 0.6;
transition: opacity 0.4s ease-in;
}
Screenshots here
I'm trying to animate a hover for a full screen background image using CSS. (Screenshots 1&2) but I also want my navigation to use my list class styles instead of the navigation I used from this tutorial. (Screenshots 3&4). How can I get the classes to function as the adjacent sibling of the hovering images instead of the anchor?
Here is my CSS
html {
background: url(scarf6.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;}
.container {
position: absolute;
overflow: hidden;
width: 100%;
height: 100%;
top:0;
left:0;
}
.container img {
position: absolute;
top: 0%;
left:0%;
z-index: -60;
height:100%;
}
.container li img {
position: absolute;
top: 0%;
left: 100%;
height:100%;
z-index: -50;
-webkit-transition: all .5s ease;
-moz-transition: all .5s ease;
-o-transition: all .5s ease;
-ms-transition: all .5s ease;
transition: all .5s ease;
}
ul {
list-style: none;
}
nav {
top:0%;
right:0%;
left:100%;
height:100%;
width:30px;
z-index: 1;
display: block;
}
li a:hover + img {
left: 0px;
}
.red {
background: #FF9999;
}
.white {
background:#FAF0E6;
}
.pink {
background: #FFC0CB;
}
.fuscia {
background:#FF0033;
}
.l1 {
height:4%;
width:100%;
}
.l2 {
height:.7%;
width:100%;
}
.l3 {
height:1.3%;
width:100%;
}
.l4 {
height:.7%;
width:100%;
}
.l5 {
height:1.3%;
width:100%;
}
.l6 {
height:.7%;
width:100%;
}
.l7 {
height:2.7%;
width:100%;
}
.l8 {
height:3.3%;
width:100%;
}
.l9 {
height:5.4%;
width:100%;
}
.l10 {
height:1.7%;
width:100%;
}
.l11 {
height:6.7%;
width:100%;
}
.l12 {
height:.8%;
width:100%;
}
.l13 {
height:4.2%;
width:100%;
}
.l14 {
height:5%;
width:100%;
}
.l15 {
height:5.8%;
width:100%;
}
.l16 {
height:3.3%;
width:100%;
}
.l17 {
height:2.5%;
width:100%;
}
.l18 {
height:1.1%;
width:100%;
}
.l19 {
height:34.5%;
width:100%;
}
.l20 {
height:3.1%;
width:100%;
}
.l21 {
height:5%;
width:100%;
}
.l22 {
height:6.2%;
width:100%;
}
And my HTML
<body>
<div class="container">
<div class="overlay">
<nav>
<li class="l1 pink">
Home
<img src="../../Cover.png" alt="">
</li>
<li>
About
<img class="hidden">
</li>
<li>
Clients
<img class="hidden">
</li>
<li>
Work
<img class="hidden">
</li>
<li>
Contact
<img class="hidden">
</li>
</nav>
</div>
</div>
</body>
Thank you for your help!
Place the image as background-image of li or a. If you don't want to display image, place it via background-position to some not-make-sence area - e.g. if image if 32px high, place it:
background-position: left 32px;
It will make this image somehow invisible. (Important note: it's better, that element with this background is as display: block). Then, when hovering, you will place image back:
...:hover {
background-position: left top;
}
I'm using this in many cases. Also when switching two images - in fact, both of them are in one image and only moving background-position when hovering.