Css Animation "fullscreen" mode - html

I have an element on screen that i would like to go full screen. I have done this, by using the following css
.fullscreen {
z-index: 2000;
width: 100%;
height: 100%;
position: fixed;
top: 0;
left: 0;
padding: 15px;
background-color: white;
}
Now i would like to have a nice animation when my element is clicked, so it looks a bit sexy as it maximizes and the same when it minimizes.
Can this be done??
I have tried transition: top .15s linear; but that doesnt seem to work
NOTE
I cannot have the element start with position:fixed using css, unless i had to use javascript to toggle it, as this is a normal html element, so i do not always want it fixed.
here is the fiddle where i got the css from to go fullscreen, so you can see what i mean. http://jsfiddle.net/a7nzy6w6/1/

The position property can't be animated. If you start with position: fixed, it's no problem.
Fiddle: http://jsfiddle.net/a7nzy6w6/299/
#myDiv.fullscreen {
z-index: 9999;
width: 100%;
height: 100%;
top: 0;
left: 0;
}
#myDiv {
position: fixed;
width: 500px;
height: 400px;
top: 20px;
left: 20px;
transition: all .15s linear;
background: #cc0000;
}
Note that using JavaScript you could find the position on the page and set it to fixed at the position as to not have to start with position: fixed, but that's outside the scope of this question.
Following up on comments to include a fade transition with CSS transition and jQuery for class toggles:
CSS:
#myDiv.fullscreen {
z-index: 9999;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
#myDiv.fade {
opacity: 0;
}
#myDiv {
width: 500px;
height: 400px;
top: 20px;
left: 20px;
background: #cc0000;
transition: opacity .15s linear;
}
JS:
$('button').click(function(e) {
var $div = $('#myDiv');
$div.toggleClass('fade');
setTimeout(function(){
$div.toggleClass('fade fullscreen');
}, 150);
});
Fiddle: http://jsfiddle.net/a7nzy6w6/308/

You need to use transition
$('button').click(function(e){
$('#myDiv').toggleClass('fullscreen');
});
#myDiv{
background:#c99;
top: 0;
left: 0;
position: fixed;
width:500px;
height:400px;
transition: all 1s ease;
}
#myDiv.fullscreen{
z-index: 9999;
width: 100%;
height: 100%;
transition: all 1s ease;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="row">
<div class="col-lg-12">
<div id="myDiv">
my div
<button>Full Screen</button>
</div>
</div>
</div>

Try this
<div class="row">
<div class="col-lg-12">
<div id="myDiv">
my div
<button>Full Screen</button>
</div>
</div>
</div>
#myDiv.fullscreen{
z-index: 9999;
min-width: 100%;
min-height: 100%;
position: fixed;
top: 0;
left: 0;
}
#myDiv{
background:#cc0000;
min-width:500px;
max-width: 500px;
min-height:400px;
transition: all 500ms;
}
live demo - http://jsfiddle.net/a7nzy6w6/306/

Related

Element shaking on Hover/Class Toggle only in Safari

I have a sidebar menu with logo toggle button which toggles the class "toggled" and on large screens also appears on hover.
The sidebar is left: 100% and on toggle/hover left: 0;
On all browsers except safari it works fine. Only on safari the logo button wiggles/shakes when letting the navigation appear.
Here a short overview of the code:
.main-navigation {
//Structure
display: inline-block;
width: 160px;
transition: all 250ms ease-in;
height: 100vh;
z-index: 100;
position: fixed;
left: -100%;
background-color: $color__primary;
&.toggled {
left: 0;
}
.menu-toggle {
margin-left: auto;
align-self: flex-end;
display: inline-block;
position: fixed;
background: none;
border: none;
border-radius: 0;
left: 20px;
top: 25px;
width: auto;
height: auto;
padding: 0;
z-index: 110;
&:focus, &:active {
outline: none;
}
}
}
And on large screens i just add the hover:
.main-navigation{
&:hover {
left: 0;
}
}
You can see it live under https://rocket.creos.agency/
I hope im just overlooking something small.
Thanks for the help!
In order to fix your problem you need to move your 'logo' from the nav element. If it is inside, like you have it's trying too animate all elements inside nav.
Here is your logic with simple code (logo is inside nav):
body {
margin: 0;
padding: 0;
}
nav {
position: fixed;
height: 100vh;
width: 160px;
left: -160px;
background-color: tomato;
-webkit-transition: all 250ms ease-in-out;
transition: all 250ms ease-in-out;
}
nav:hover {
left: 0;
}
button {
position: fixed;
top: 10px;
left: 10px;
}
.content {
margin-top: 50px;
}
<nav>
<button>
Hover me
</button>
<div class='content'>
<ul>
<li>
one
</li>
<li>
two
</li>
</ul>
</div>
</nav>
And this is when 'logo' is outside the nav:
(() => {
const btn = document.getElementById('animateNav');
const nav = document.getElementById('navigation');
const content = document.getElementById('content');
btn.addEventListener('mouseover', () => {
nav.classList.add("animate");
});
nav.addEventListener('mouseout', () => {
nav.classList.remove("animate");
});
nav.addEventListener('mouseover', () => {
nav.classList.add("animate");
});
content.addEventListener('mouseover', () => {
nav.classList.add("animate");
});
})();
body {
margin: 0;
padding: 0;
}
nav {
position: fixed;
height: 100vh;
width: 160px;
left: -160px;
background-color: tomato;
-webkit-transition: all 250ms ease-in-out;
transition: all 250ms ease-in-out;
}
nav.animate {
left: 0;
}
button {
position: fixed;
top: 10px;
left: 10px;
}
#content {
margin-top: 50px;
}
<nav id='navigation'>
<div id='content'>
<ul>
<li>
one
</li>
<li>
two
</li>
</ul>
</div>
</nav>
<button id='animateNav'>
Hover me
</button>
All difference is in second example that you need to toggle a class for nav using JavaScript. I provided not efficient logic to toggle a class, but I just wanted to present to you working solution.
P.S. don't use <a> tag inside of <button> tag

overflow:hidden not working with border-radius in Chrome

I'm trying to make a circle-shaped image with an overlay that shows on hover. However, the "hitbox" of hovering (and clicking) is incorrect, as shown in the snippet below.
This issue seems to only occur in Chrome (not sure about Safari). I've found some fixes on the Internet, but none of them worked. JSFiddle for testing
$(document).ready(function() {
$(".circle").click(function() {
alert($(this).attr("id"));
});
});
#canvas {
width: 100%;
padding-bottom: 75%;
position: relative;
overflow: hidden;
background-color: #eee;
}
.circle {
position: absolute;
width: 25%;
padding-bottom: 25%;
border-radius: 50%;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
overflow: hidden;
cursor: pointer;
/*https://stackoverflow.com/a/32987370/5532169*/
-webkit-backface-visibility: hidden;
-moz-backface-visibility: hidden;
/*https://stackoverflow.com/a/25206004/5532169*/
z-index: 1;
/*https://stackoverflow.com/a/10296258/5532169*/
-webkit-mask-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAA5JREFUeNpiYGBgAAgwAAAEAAGbA+oJAAAAAElFTkSuQmCC);
/*https://stackoverflow.com/a/16878347/5532169*/
-webkit-mask-image: -webkit-radial-gradient(circle, white, black);
}
.mid {
width: 100%;
height: 100%;
position: absolute;
}
.inner {
width: 100%;
height: 100%;
position: relative;
}
.inner>* {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
width: 100%;
height: 100%;
}
.hover {
background-color: rgba(255, 255, 255, 0.6);
opacity: 0;
transition: opacity 0.5s;
}
.hover:hover {
opacity: 100;
transition: opacity 0.5s;
}
span {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 72%;
text-align: center;
font-family: monospace;
font-size: 2em;
font-weight: bold;
color: #08f;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="canvas">
<div id="div1" class="circle">
<div class="mid">
<div class="inner">
<img src="https://dummyimage.com/320x320/000/fff" alt="">
<div class="hover">
<span>Hello World!</span>
</div>
</div>
</div>
</div>
</div>
Edit: Tested in Firefox 57, works without problem. IE and Edge were tested already, so it's a Chrome-/webkit-specific issue.
The blocks in HTML are square defined by position (x, y) and size (width, height) so the browser can have a simplified idea of what is on the page and interact with. So even with border-radius, mask-image, etc... your .circle div is still a square with coming drawn within.
To avoid that, you can't use a dynamic selector like :hover because it will use the shape of the div and that is a square. You need to use javascript to detect mouse position when hovering your block and with that execute an animation (with sinus and cosinus calculation).
You can get the mouse position with something like this :
<div class="circle" onmouseover="hoverFunction(e)"></div>
<script>
function hoverFunction(e) {
var x = e.clientX;
var y = e.clientY;
}
</script>
I also found this topic talking about getting elements position on the page.
You can change only .circle class these properties:
width: 26%;
padding-bottom: 26%;
border-radius: 50%;
-moz-border-radius: 50%;
-webkit-border-radius: 50%;

CSS: Reduce element size on hover, but keep original "hover area"

I want to reduce element size a bit as an effect, when it is hovered over with a mouse. However, this looks buggy because as the element reduces in size, the "hover area" gets smaller as well, which can result into the element not being hovered anymore, which further results into this "size flickering".
Is there a proper way to implement element size reduction on hover, while keeping the hover area size the same? Without extra elements?
Here is a fiddle: https://jsfiddle.net/ahvonenj/88f5by59/
Required code for fiddle linking:
#di
{
position: absolute;
left: 15px;
top: 15px;
background-color: #2980b9;
box-sizing: border-box;
width: 100px;
height: 100px;
}
#di:hover
{
width: 50px;
height: 50px;
transition: all 200ms linear;
}
Wrapping it in a div would be better, as commented. But if adding no other elements is a must, you could work with pseudo elements.
Make the visible part a pseudo element (like :before), and keep the main one just for hovering:
TIP: If you want the transition effect on both mouse over and out, set the property to the main css rule, not to the hover one
#di
{
position: absolute;
left: 15px;
top: 15px;
box-sizing: border-box;
width: 100px;
height: 100px;
}
#di:before {
content: "";
display: block;
background-color: #2980b9;
width: 100px;
height: 100px;
}
#di:hover:before
{
width: 50px;
height: 50px;
transition: all 200ms linear;
}
<div id = "di">
</div>
You can wrap the div inside a container and "bind" the hover event to the parent.
P.S obviously it is a solution with adding other elements.
#container
{
position: absolute;
left: 15px;
top: 15px;
box-sizing: border-box;
}
#container, #di{
width: 100px;
height: 100px;
}
#di{
background-color: #2980b9;
}
#container:hover #di
{
width: 50px;
height: 50px;
transition: all 200ms linear;
}
<div id="container">
<div id="di">
</div>
</div>
Yep, this is your answer. You have to add one more element. See this fiddle:
https://jsfiddle.net/vwy4utf5/
html:
<div id = "di">
<div id="diin">
</div>
</div>
CSS
#di{width:101px; height:101px; cursor:pointer; position: absolute;
left: 15px;
top: 15px;}
#diin
{
background-color: #2980b9;
box-sizing: border-box;
width: 100px;
height: 100px;
transition: all 200ms linear;
}
#di:hover > div
{
width: 50px;
height: 50px;
transition: all 200ms linear;
}
I tried it using Jquery, didn't specified by OP but I guess it can help somebody.
So changed css to make parent positioning of new parent:
#di {
background-color: #2980b9;
box-sizing: border-box;
width: 100px;
height: 100px;
}
#di_parent {
padding: 0;
overflow: hidden;
position: absolute;
left: 15px;
top: 15px;
}
#di_parent:hover > DIV {
width: 50px;
height: 50px;
transition: all 200ms linear;
}
Then added some JQuery to create a container to each object to maitain size as is suggested above.
$('#di').each(function(i, v){
var o, p;
o=$(v);
p=$('<div id="di_parent"></div>');
p.css({height:o.outerHeight(),width:o.outerWidth()});
o.after(p);
p.append(o.detach());
});
Working fiddle:
https://jsfiddle.net/88f5by59/11/
$('#di').each(function(i, v){
var o, p;
o=$(v);
p=$('<div id="di_parent"></div>');
p.css({height:o.outerHeight(),width:o.outerWidth()});
o.after(p);
p.append(o.detach());
});
#di {
background-color: #2980b9;
box-sizing: border-box;
width: 100px;
height: 100px;
}
#di_parent {
padding: 0;
overflow: hidden;
position: absolute;
left: 15px;
top: 15px;
}
#di_parent:hover > DIV {
width: 50px;
height: 50px;
transition: all 200ms linear;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<div id = "di">
</div>
Hope it helps!

Change backgroundImage opacity css without changing text in it Opacity

I have a div which has an background image set. There is some text in this div as well.
I want to have full opacity all the time. On mouse over the background image must change from 0.5 to 1 opacity.
#cover {
background: url(http://animalscamp.com/wp-content/uploads/2011/12/Grizzly-Bear-3.jpg);
width: 100%;
height: 100%;
filter: alpha(opacity=40);
opacity: 0.5;
}
#cover:hover {
opacity: 1;
}
<div class="col-12" id="cover">
<h2>ABC</h2>
<p>WELCOME USER</p>
</div>
Use a div inside a div to serve the background:
http://jsfiddle.net/0mgrt069/9/ (just fixed a typo)
<div class="col-12">
<div class="background"></div>
<h2>ABC</h2><p>WELCOME USER</p>
</div>
And CSS:
.background{
background:url(http://animalscamp.com/wp-content/uploads/2011/12/Grizzly-Bear-3.jpg);
position: absolute;
z-index: -1;
top: 0;
bottom: 0;
left: 0;
right: 0;
opacity: .4;
width: 300px;
height: 200px;
}
.background:hover{
opacity:1;
}
Rather than adding an extra element, why don't you think of using pseudo elements? you could then 'alter' the background opacity on the hover:
Something like:
#cover:after {
content: "";
position: absolute;
height: 100%;
width: 100%;
top: 0;
background: url(http://animalscamp.com/wp-content/uploads/2011/12/Grizzly-Bear-3.jpg);
opacity: 0.5;
z-index:-2;
}
whilst making your #cover have a position: relative.
Live Demo
#cover {
position: relative;
background: width: 100%;
height: 100%;
}
#cover:hover:after {
opacity:1;
}
#cover:after {
content: "";
position: absolute;
height: 100%;
width: 100%;
top: 0;
background: url(http://animalscamp.com/wp-content/uploads/2011/12/Grizzly-Bear-3.jpg);
opacity: 0.5;
z-index:-2;
}
<div class="col-12" id="cover">
<h2>ABC</h2>
<p>WELCOME USER</p>
</div>
Try this fiddle. Set the opacity of text to original opacity of image or as per your requirement of opacity value for text.
http://jsfiddle.net/pradyumnaswain/Lpmkq6of/
#cover {
background: url(http://animalscamp.com/wp-content/uploads/2011/12/Grizzly-Bear-3.jpg);
width: 100%;
height: 100%;
filter: alpha(opacity=40);
opacity: 0.5;
}
#cover:hover {
opacity: 1;
}
h2 {
opacity: 0.5
}
p {
opacity: 0.5
}
<div class="col-12" id="cover">
<h2>ABC</h2>
<p>WELCOME USER</p>
</div>

Higher z-index does not change stacking order

What I am trying to do is, when the user hover on the image the image should reposition along the x-axis and it should reveal the .content. i have set z-index: 10 to image and z-index: 1 to .content to make .content to be underneath the image. but .content still remains on top of the image. Please help me..
Here is my code:
html
<div class="holder">
<img src="http://placehold.it/350x150" />
<div class="content">
<h3>hello there</h3>
view more
<div/>
</div>
css
.holder {
margin-top: 130px;
position: relative;
}
img {
display: block;
transition: -webkit-transform 0.5s;
transition: -moz-transform 0.5s;
z-index: 10;
}
.content {
background: blue;
height: 100%;
color: white;
z-index: 1;
position: absolute;
top: auto;
bottom: 0;
}
a {
color: white;
background: red;
padding: 10px;
}
.holder:hover img {
-webkit-transform: translateX(90px);
-moz-transform: translateX(90px);
}
Here I corrected issue of my code thanks to Jones G. Drange. As he pointed out in his comment
"z-index can only be modified in elements with a position other than static. Your img has position: static by default"
jsfiddle
img {
position: relative;
}