i'm trying to set up a navigation with cross fading images besides the nav. But placing the between the is not working.
So my intention is if home, about, work or contact is clicked the( one page ) will load the content and the navigation shows the right image of the current page.
HTML: <div id="cf7" class="shadow">
<img class='opaque' src="/images/Cirques.jpg" />
<img src="/images/Clown%20Fish.jpg;" />
<img src="/images/Stones.jpg;" />
<img src="/images/Summit.jpg;" />
</div>
<p id="cf7_controls">
<span class="selected">Home</span>
<span>About</span>
<span>Work</span>
<span>Contact</span>
</p>
CSS
p#cf7_controls {
text-align:center;
}
#cf7_controls span {
padding-right:2em;
cursor:pointer;
}
#cf7 {
position:relative;
height:281px;
width:450px;
margin:0 auto 10px;
}
#cf7 img {
position:absolute;
left:0;
-webkit-transition: opacity 1s ease-in-out;
-moz-transition: opacity 1s ease-in-out;
-o-transition: opacity 1s ease-in-out;
transition: opacity 1s ease-in-out;
opacity:0;
-ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=0)";
filter: alpha(opacity=0);
}
#cf7 img.opaque {
opacity:1;
-ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=100)";
filter: alpha(opacity=1);
}
JAVASCRIPT
$(document).ready(function() {
$("#cf7_controls").on('click', 'span', function() {
$("#cf7 img").removeClass("opaque");
var newImage = $(this).index();
$("#cf7 img").eq(newImage).addClass("opaque");
$("#cf7_controls span").removeClass("selected");
$(this).addClass("selected");
});
});
That's a very unusual way to build a navigation. You don't even use anchor tags; those have the highest compatibility with older browsers for states like :hover.
For your example you need a syntax like this, for displaying the right images:
<span>About</span>
span {
background-image: none;
}
span#your_span_id:hover, span.selected {
background-image: url('path/to/your/img');
}
However, if you want to load content on one page, you will need at least javascript/ jquery to dynamically add/remove the '.selected' class. One CSS workaround is to nest your content divs in the navigation (and display: hide them, on hover show them), but in that case you need to specify the cursor for every element inside your content divs, and as soon as your visitors mouse out of the content div, it will disappear. Click events= javascript
Related
I am working on a web app. When a user visits the landing page, I want to fade-in an image. That image is the background for some text. When the image has successfully loaded, I then want to move the text in from the top. Currently, I have the following:
<html>
<head>
<title></title>
<style type="text/css">
.banner {
background-image: url('/public/img/bg.png');
background-size: cover
}
#keyframes fadeIn { from { opacity:0; } to { opacity:1; }}
.fade-in {
opacity:0;
animation:fadeIn ease-in 1;
animation-fill-mode:forwards;
animation-duration:0.2s;
}
#keyframes translateY { from { y:0px; } to { y:100px; } }
.translate-y {
animation:translateY ease-in 1;
animation-duration:0.1s;
animation-fill-mode:forwards;
}
</style>
</head>
<body>
<div class="banner fade-in">
<h1 class="translate-y">Welcome</h1>
</div>
</body>
</html>
There are several problems with this approach:
The animation starts whether the background-image is loaded or not.
The "Welcome" text starts animating before the background-image is loaded.
I'm not sure how to fix this. The first item is especially frustrating. I can't use jQuery, so I'm stuff with CSS. The second item, I could use an offset. However, once again, if the image isn't cached, nothing runs properly.
Place your image in the background with an <img ...> tag, (not with CSS background-image: ... attribute).
You can set the initial opacity to 0, and when the image onloaded, set the opacity to 1. With CSS you can make a transition between the two states:
<style>
.easeload{
opacity: 0;
-webkit-transition: all 2s ease;
-moz-transition: all 2s ease;
-ms-transition: all 2s ease;
-o-transition: all 2s ease;
}
</style>
<img class="easeload" onload="this.style.opacity=1" src="https://dummyimage.com/320x240">
I have seen this problem before, there is a solution I have used myself from this css-tricks article, but just in case the link does go dead here is the solution: You need to add a class/id to your body to ensure that everything transitions/animations and anything you need CSS runs after the body loads. The below is an example of what you can achieve, keep in mind you can add anything else you need under the #preload id.
CSS
#preload * {
-webkit-transition: none !important;
-moz-transition: none !important;
-ms-transition: none !important;
-o-transition: none !important;
}
HTML
<body id="preload">
JS
// trigger right as the document loads
document.getElementById("preload").className = "";
Give it a try and let us know if this worked for you.
You can use animation-delay and add it to the elements.It should solve your problems :
animation-delay: 2s;
I am trying to add a simple ease-in and ease-out effect when you hover over a logo. I know there are posts about this. I've tried many different combinations of CSS, but can't seem to get it to work.
I've successfully changed the logo color by changing the content upon hover with this CSS code:
#dealertrackr-image.et_pb_image:hover {
content: url('image url');
}
When it is hovered over, the logo changes from the black and white state to colored state. I now want this to have a 1s ease-in and ease-out on hover and release of hover. Nothing that I tried worked.
http://www.nationalgalactic.com/divisions/
If all you were hoping for was grayscale, you may also be interested in just loading in the full color image and using a CSS filter to desaturate / resaturate on hover.
This combined with CSS transitions will create a nice little fade:
img {
-webkit-filter: grayscale(100%);
filter: gray; filter: grayscale(100%);
filter: url(desaturate.svg#greyscale);
-webkit-transition: all .25s ease;
-moz-transition: all .25s ease;
transition: all .25s ease;
}
img:hover {
-webkit-filter: grayscale(0%);
filter: none;
}
*edit
This is a pure CSS solution, but is not fully supported in Android Jellybean, and Internet Explorer. If full browser support is important to you, please see isherwood's answer on this same post. For full support, your solutions are limited to stacked images or javascript.
The only way to do it with images is to stack elements and transition the opacity of the top layer. Browsers don't do image-to-image transitions.
Something like this, where the anchor has a background image:
a {
display: inline-block;
background: url(http://lorempixel.com/400/150/nature) left top no-repeat;
}
a img {
transition: opacity 1s;
}
a:hover img {
opacity: 0;
}
<a href="#">
<img src="http://lorempixel.com/400/150/nature/2" alt="">
</a>
Here's a demo with your code and images.
Background:
Finding improved ways to use CSS, I came across the proposition of using image transitions for good effects.
After a few stumbles, I managed to do this with the help of some references to make a smooth transition in hover.
Now I want it automatic and with links in each picture, but I'm at a loss at the code.
Current JSFiddle:
None, JSFIDDLE doesn't accept IMG and I can't show there.
<div class="container">
<img src="sky.jpg">
<img class="front" src="bear.jpg">
</div>
.container
{
position:relative;
height:500px;
width:500px;
margin:0 auto;
}
.container img
{
position:absolute;
transition: opacity 1s ease-in-out;
}
.container img.front:hover
{
opacity:0;
}
Problem:
This HTML-CSS works but for a single image switch (2 images) on hover, not for multiple ones automatically.
Need:
A change in the code which allows multiple switches using CSS and HTML only, with different links on each image.
I know there are possibilities with JQUERY and JAVACRIPT, I wish for a solution without these two.
Solution Code restrictions and parameters:
No JQUERY nor JAVASCRIPT
Multiple browser compatibility (doesn't need to be very old ones)
Possibility of multiple links in each image switch
Many Thanks for all help provided.
Try this you have to move your cursor a slight (shake it a bit) to see the change in the link notice the change in the link http://jsfiddle.net/fc3nb5rL/1/
i used z-index instead of opacity
.back {
z-index:1;
}
#-webkit-keyframes anim {
from {
z-index:1;
}
to {
z-index:-2;
}
}
.back:hover {
-webkit-animation:anim 5s;
-webkit-animation-iteration-count:infinite;
-webkit-animation-timing-function: ease-in-out;
}
#-webkit-keyframes anim2 {
from {
z-index:1;
}
to {
z-index:-2;
}
}
.front:hover{
-webkit-animation:anim2 5s;
-webkit-animation-iteration-count:infinite;
-webkit-animation-timing-function: ease-in-out;
}
I have two collections of elements I want to make inter-dependent (binded to each other)
On the one hand I have some text links in a navigation bar, on the other hand I have some elements with references to the same links. These images have animation effects, as described below (the animation occurs when hovering the images).
I want to achieve the following behavior: when hovering over links in the nav. bar, I would like to activate the hovering effects on the images. ¿Is that possible without jQuery?
This is the style of the animated elements
.view-first img {
transition: all 0.2s linear;
}
.view-first .mask {
opacity: 0;
background-color:rgba(116,89,47,0.8);
transition: all 0.4s ease-in-out;
}
.view-first h2 {
transform: translateY(-100px);
opacity: 0;
transition: all 0.2s ease-in-out;
}
.view-first p {
transform: translateY(100px);
opacity: 0;
transition: all 0.2s linear;
}
.view-first a.info{
opacity: 0;
transition: all 0.2s ease-in-out;
}
.view-first:hover img {
transform: scale(1.1);
}
.view-first:hover .mask {
opacity: 1;
}
.view-first:hover h2,
.view-first:hover p,
.view-first:hover a.info {
opacity: 1;
transform: translateY(0px);
}
.view-first:hover p {
transition-delay: 0.1s;
}
.view-first:hover a.info {
transition-delay: 0.2s;
}
This is the markup of the navigation elements
<nav><ul>
<li>DSIC</li>
<li>RNA</li>
<li>De Ludo Bellico</li>
</ul></nav>
This is the markup for one of the images with animation effects
<div class="view view-first">
<img src="images/animage.png" />
<div class="mask"/>
<div class="content">
<h2>Name</h2>
<p>Description</p>
Take me there!
</div>
</div>
So, when hovering over elements in the navigation bar , I would like to fire the animation in the associated "view" element
For what I have read, it seems that behaviour can be achieved by using jQuery (or js). But, ¿is it possible to achieve the same effect using pure html and css ? ¿how?
The following picture shows the layout of my page. When hovering in the elements of the navigation bar, in blue, I want to fire an animation in the pictures below.
The strict answer is no, it is not possible to make any element x run the animation for element y when you hover over it. However, you could use pure CSS in the following situations:
1) Your focused element is a parent of .view-first
.y:hover .view-first { ... }
2) Your focused element is adjacent to .view-first
.y:hover + .view-first { ... }
3) Your focused element is a general sibling of .view-first
.y:hover ~ .view-first { ... }
Interestingly, the current proposals for CSS4 include the addition of a "subject selector", which allows you to set the "subject" in your selectors using a !, and thus select upwards in the DOM. (See the current W3C spec - Thanks to Alohci for the link). This would also be useful for this situation, but would still not allow you to select "anything", the elements would have to be related in some way.
Edit
Mr. Alien points out that using the :target pseudo-class could be useful, if you were to allow clicking the element. Lets say you had your HTML as
Start Spin
<div id="spin" class="view-first"></div>
you could then use the target to initiate the spin, by having your CSS as:
.view-first:target { ... }
Though I'm not sure if that helps you too much.
Edit 2019 - The subject selector (!) has been replaced with the :has() selector, but it's still entirely unsupported across browsers (5 years on!)
You can try this:
.view-first { opacity: 0;
/*more properties here*/}
.myDiv:hover ~ .view-first{
-webkit-animation: boxanimation 1.5s;
opacity: 1;
-webkit-transition: all 0s;
-webkit-animation-fill-mode: initial;
/*more properties here*/}
This will work for chrom and safary, for more broser you can set the -moz for firefox, and -o for opera
Im trying to create spinners for Twitter Bootstrap buttons. Spinners should indicate some work in progress (ie. ajax request).
Here is small example:
http://jsfiddle.net/AndrewDryga/zcX4h/1/
HTML (full on jsfiddle):
Unknown element (no animation here!):
<p>
<button class="btn-success has-spinner">
<span class="spinner"><i class="icon-spin icon-refresh"></i></span>
Foo
</button>
</p>
Works when width is defined:
<p>
<a class="btn btn-success has-spinner">
<span class="spinner"><i class="icon-spin icon-refresh"></i></span>
Foo
</a>
</p>
CSS:
.spinner {
display: inline-block;
opacity: 0;
width: 0;
-webkit-transition: opacity 0.25s, width 0.25s;
-moz-transition: opacity 0.25s, width 0.25s;
-o-transition: opacity 0.25s, width 0.25s;
transition: opacity 0.25s, width 0.25s;
}
/* ... */
.has-spinner.active .spinner {
opacity: 1;
width: auto; /* This doesn't work, just fix for unkown width elements */
}
/* ... */
.has-spinner.btn.active .spinner {
width: 16px;
}
.has-spinner.btn-large.active .spinner {
width: 19px;
}
The deal is that css "margin: auto" doesn't produce expected animation and spinner widths for all elements should be defined via css. Is there are any way to solve this problem? Also, maybe there are better way to align/show spinners?
And should i play with buttons padding and make it in way, where button width doesn't change, when spinner is shown or buttons that change width is ok? (If ill put it as snippet somewhere)
I was able to fix this problem by using max-width istead of width. Also this is pure CSS solution, so it can be used pretty much everywhere (for example show X mark on tags, when user hover mouse over it, etc).
Demo: http://jsfiddle.net/AndrewDryga/GY6LC/
New CSS:
.spinner {
display: inline-block;
opacity: 0;
max-width: 0;
-webkit-transition: opacity 0.25s, max-width 0.45s;
-moz-transition: opacity 0.25s, max-width 0.45s;
-o-transition: opacity 0.25s, max-width 0.45s;
transition: opacity 0.25s, max-width 0.45s; /* Duration fixed since we animate additional hidden width */
}
/* ... */
.has-spinner.active .spinner {
opacity: 1;
max-width: 50px; /* More than it will ever come, notice that this affects on animation duration */
}
I have updated #andrew-dryga solution to use the currently latest Bootstrap (3.3.5), font-awesome (4.3.0), jQuery (2.1.3) and slightly modified it.
Here it is:
<button class="btn btn-success has-spinner">
<i class="fa fa-spinner fa-spin"></i>
Foo
</button>
$('a.has-spinner, button.has-spinner').click(function() {
$(this).toggleClass('active');
});
In addition, you need appropriate CSS modifications (JSFiddle).
I found your code to be super helpful. I know it's been a year but I've improved upon the code. I didn't like having to manually add the span and i tags to each element. I tweaked the JavaScript code to add these tags automatically. So all you have to do to add a spinner to a button/link is add the has-spinner class to it and give it a data-spinner="[left|right]" tag (determines which side of your button text the spinner should be placed).
Here's the modified JavaScript:
$(function(){
var spinnerHTML = "<span class='spinner'><i class='fa fa-refresh fa-spin'></i></span>",
spinnerObjects = $(".has-spinner");
spinnerObjects.filter("[data-spinner=left]").prepend(spinnerHTML + " ")
spinnerObjects.filter("[data-spinner=right]").append(" " + spinnerHTML)
spinnerObjects.click(function() {
$(this).toggleClass('active');
});
});
Here's the link to the fiddle with all the changes (CSS,HTML):
http://jsfiddle.net/codyschouten/QKefn/2/
Very simple solution worked for me was changing the element from
<i></i>
with
<em></em>
This was the only change I did.