I'm trying to change the background image when the item is clicked. I want a cover photo - when clicked and opened the image changes to a background photo.
.el:nth-child(1) {
transform: translate3d(0%, 0, 0);
transform-origin: 50% 50%;
}
.cont.s--el-active .el:nth-child(1):not(.s--active) {
transform: scale(0.5) translate3d(0%, 0, 0);
opacity: 0;
transition: transform 0.95s, opacity 0.95s;
}
.el:nth-child(1) .el__inner {
transition-delay: 0s;
}
.el:nth-child(1) .el__bg {
transform: translate3d(0%, 0, 0);
}
.el:nth-child(1) .el__bg:before {
transition-delay: 0s;
background-image:
url("https://cdn.shopify.com/s/files/1/2084/8209/files/IMG_8289.JPG?
13764159910008904703");
}
I want to add a second image as this currently displays only one image as when closed and opened.
Here is what I'm trying to replicate from CodePen
I should mention I have converted the SCSS to CSS
You can rely on the active class set there:
.el:nth-child(1).s--active .el__bg:before {
background-image: url("https://s3-us-west-2.amazonaws.com/s.cdpn.io/142996/onepgscr-3.jpg")!important;
}
Or use :after so you are able to do some transitions instead of replacing first image directly.
So I have a graph that is filled out through a nice animation. This happens because every bar in the graph has the css attribute
animation: slide-left 0.9s ease-in-out 1s both;
The animation looks like this:
#keyframes slide-left {
0% {
-webkit-transform: translateX(-200%);
}
70% {
-webkit-transform: translateX(2%);
}
100% {
-webkit-transform: translateX(0);
}
}
Now, I'm not very good at javascript but I'd like this to happen on the click of a button (and have the graph hidden until the button is clicked) instead of when the page loads.
Now I've removed the animation-attribute from the css-selector and added translateX(-200%);
Realized that if I add animation: slide-left 0.9s ease-in-out 1s both; through inspect element, exactly what I want happens.
So I found a "solution" that looks like this:
$("#button").on('click', show_function);
function show_function() {
$(".graph").fadeIn("slow");
$('<style>.bar-container>* { animation: slide-left 1s ease-in-out 1s both; }</style>').prependTo('body');
}
This feels "clunky" and it takes almost a second to load. So I was wondering what a better way to have a function trigger the animation in javascript/JQuery would be?
Your best answer is likely to be have the animation sequence in a class, and use jQuery to add the class. E.g.
CSS
#keyframes slide-left {
0% {
-webkit-transform: translateX(-200%);
}
70% {
-webkit-transform: translateX(2%);
}
100% {
-webkit-transform: translateX(0);
}
}
.slide-it {
animation: slide-left 0.9s ease-in-out 1s both;
}
And then JS
$("#button").on('click', show_function);
function show_function() {
$(".graph").fadeIn("slow");
$('.bar-container').addClass('slide-it');
}
I have applied a transform: -webkit-transform: skewY(170deg) on an element.
Its working fine.
Afterwards, i add to the skewed element a class that animates a scaleOut.
This is the animation:
.partialScaleOutAnimation{
-webkit-animation: partialScaleOut 0.5s;
}
#-webkit-keyframes partialScaleOut {
0%{
-webkit-transform: scale(1);
}
100%{
-webkit-transform: scale(0.3);
}
}
for some reason when applying the animation, the skewed effect disappears. Why?
So I am making a website and can make the CSS animation work for when the page is first called but I want it to call everytime the AJAX function is called. Here is the javascript XML call which works
function XML(infoId)
{
var xmlHttp = xmlHttpObjCreate();
if (!xmlHttp) {
alert("The browser doesn't support this action.");
return;
}
xmlHttp.onreadystatechange=function() {
if(xmlHttp.readyState == 4 && xmlHttp.status == 200) {
elemObj = document.getElementById('textbox');
elemObj.innerHTML = xmlHttp.responseText;
elemObj.className = "bounceInUp";
}
}
// Append GET data to identify which quote we want
var reqURL = "FILE_NAME_HERE_?infoId=" + infoId;
xmlHttp.open("GET", reqURL, true);
xmlHttp.send();
}
Here is an example of what calls the function
Here is the CSS animation code which is named is "bounceInUp"
#textbox {
width: 100%;
background-color: transparent;
height: 200px;
color: #0000FF;
font-weight: bold;
font-size: 22px;
overflow: auto;
padding: 10;
-webkit-animation: bounceInUp 1200ms ease-out;
-moz-animation: bounceInUp 1200ms ease-out;
-o-animation: bounceInUp 1200ms ease-out;
animation: bounceInUp 1200ms ease-out;
}
#-webkit-keyframes bounceInUp {
0%, 60%, 75%, 90%, 100% {
-webkit-transition-timing-function: cubic-bezier(0.215, 0.610, 0.355, 1.000);
transition-timing-function: cubic-bezier(0.215, 0.610, 0.355, 1.000);
}
0% {
opacity: 0;
-webkit-transform: translate3d(0, 3000px, 0);
transform: translate3d(0, 3000px, 0);
}
60% {
opacity: 1;
-webkit-transform: translate3d(0, -20px, 0);
transform: translate3d(0, -20px, 0);
}
75% {
-webkit-transform: translate3d(0, 10px, 0);
transform: translate3d(0, 10px, 0);
}
90% {
-webkit-transform: translate3d(0, -5px, 0);
transform: translate3d(0, -5px, 0);
}
100% {
-webkit-transform: translate3d(0, 0, 0);
transform: translate3d(0, 0, 0);
}
}
#keyframes bounceInUp {
0%, 60%, 75%, 90%, 100% {
-webkit-transition-timing-function: cubic-bezier(0.215, 0.610, 0.355, 1.000);
transition-timing-function: cubic-bezier(0.215, 0.610, 0.355, 1.000);
}
0% {
opacity: 0;
-webkit-transform: translate3d(0, 3000px, 0);
transform: translate3d(0, 3000px, 0);
}
60% {
opacity: 1;
-webkit-transform: translate3d(0, -20px, 0);
transform: translate3d(0, -20px, 0);
}
75% {
-webkit-transform: translate3d(0, 10px, 0);
transform: translate3d(0, 10px, 0);
}
90% {
-webkit-transform: translate3d(0, -5px, 0);
transform: translate3d(0, -5px, 0);
}
100% {
-webkit-transform: translate3d(0, 0, 0);
transform: translate3d(0, 0, 0);
}
}
.bounceInUp {
-webkit-animation-name: bounceInUp;
animation-name: bounceInUp;
}
I apologize for all the code but I want to make sure everything is here that someone may need to help me. So as of right now the css animation only runs when the page is first loaded not when the XML function is called.
It looks like you are already attaching the animation via the #textbox CSS selector. And your AJAX call adds a class name that appears to have the exact same animation properties that are already applied to the textbox via the #textbox rule.
In order to get your animation to fire again, I suspect you need to clear the animation CSS property off of your #textbox before the AJAX call is sent, then your AJAX call will reapply the animation. You can do this a variety of ways, one off the top of my head would be to create a separate class that clears the animation and apply that classname to #textbox before you do your xmlHttp.send(), that way the textbox is back to a non-animated state before your success handler from the AJAX call reapplies the animation.
To simplify it, you may just want to remove the animation properties from the #textbox CSS rule and just apply and remove the .bounceInUp class name to the element when you want the animation to run. I think that's a cleaner approach.
You can use classList:
this.classList.remove('bounceInUp');
this.classList.add('bounceInUp');
That will re-apply the class and make the bounce happen again. It is simpler and more readable than setTimeout. You're fine with classList since you're using keyframes - each will work on IE10 and above.
I'm attempting to create a pulsing animation of an element using CSS3's transform: scale(x,y). I want the object to endlessly pulse (becoming slightly larger) unless it's hovered over - at which point the current animation should finish (i.e. return to its original size) and cease pulsing until it's no longer being hovered over. I can't even seem to get jQuery's .animate() to work, however.
function pulse() {
$('#pulsate').animate({
transition: 'all 1s ease-in-out',
transform: 'scale(1.05,1.05)'
}, 1500, function() {
$('#pulsate').animate({
transition: 'all 1s ease-in-out',
transform: 'scale(1,1)'
}, 1500, function() {
pulse();
});
});
}
pulse();
Would using .addClass and .removeClass be better here? .removeClass would do the trick for stopping the animation on .hover(), but I'm unsure on implementation overall.
Try using CSS animations.
#keyframes pulse {
0% {
transform: scale(1, 1);
}
50% {
transform: scale(1.1, 1.1);
}
100% {
transform: scale(1, 1);
}
}
#test {
animation: pulse 1s linear infinite;
}
#-webkit-keyframes pulse {
0% {
-webkit-transform: scale(1, 1);
}
50% {
-webkit-transform: scale(1.1, 1.1);
}
100% {
-webkit-transform: scale(1, 1);
};
}
#keyframes pulse {
0% {
transform: scale(1, 1);
}
50% {
transform: scale(1.1, 1.1);
}
100% {
transform: scale(1, 1);
};
}
#test {
background: red;
width: 20px;
height: 20px;
-webkit-animation: pulse 1s linear infinite;
animation: pulse 1s linear infinite;
}
#test:hover {
-webkit-animation: none;
animation:none;
}
<div id="test"></div>
http://jsfiddle.net/rooseve/g4zC7/2/