SASS - Transition mixin with var args and shared args - sass

Here's what I'm trying to do, I'd like to create a mixin that allows a variable number of properties, and also allows me to use single DRY vals for (in this example) a transition.
So I could say, "transition the box-shadow, border, and width # .2s with a ease-in."
Here's some pretty serious psuedo-code off the top of my head. The part I'm most unsure about is how to take the list so that it compiles in the proper way. I wasn't sure if append would be the right way, or if I needed to concatenate a string var, or what?
/* move object*/
.moveit{
#include grouped-trans((box-shadow, border, width), 0.2s, ease-in);
}
/* mixin */
#mixin grouped-trans($list, $time, $ease)
{
#each $prop in $list {
//transition: append($prop, $time, $ease);
// - or -
//$tmp_var + $list, $time, $ease;
}
I know there are ways to incorporate variable args using methods like string interpolation #{} and including '...' as a parameter. But I - ideally - would like to find a way to execute this in the way I described.

Here's how you build the mixin you're looking for. Note that this does require use of Compass, but it's silly to use Sass without using Compass.
#import "compass";
#mixin grouped-trans($list, $time, $ease) {
#include transition-property($list);
#include transition-duration($time);
#include transition-timing-function($ease);
}
.moveit {
#include grouped-trans((box-shadow, border, width), 0.2s, ease-in);
}
The above SCSS will compile to the following CSS:
.moveit {
-webkit-transition-property: box-shadow, border, width;
-moz-transition-property: box-shadow, border, width;
-o-transition-property: box-shadow, border, width;
transition-property: box-shadow, border, width;
-webkit-transition-duration: 0.2s;
-moz-transition-duration: 0.2s;
-o-transition-duration: 0.2s;
transition-duration: 0.2s;
-webkit-transition-timing-function: ease-in;
-moz-transition-timing-function: ease-in;
-o-transition-timing-function: ease-in;
transition-timing-function: ease-in;
}

Related

CSS compiles the lighten( ) function and the similar SASS colors' functions in a way that does not seem right

CSS compiles the following mixin code:
#mixin message ($color, $background-color: lighten ($color, 20%) ) {
color: $color;
background-color: $background-color;
}
.message-danger { #include message(red); }
to this
.message-danger {
color: red;
background-color: lighten red, 20%;
}
Obviously you can see that CSS did not compile the lighten( ) function properly. I tried to change the color to a hex code color but that made no difference. I thought the problem was from my code editor, but when I tried the code on sassmeister it gave me the same result. Please help.

Updating variables created by lighten/darken functions by modifying the original base color afterwards

I'm currently trying to create a mix-in that will let me build buttons with hover values using the darken and lighten color functions in sass. My code for some reason is spitting out white and black for the background color instead of the hex value of a returned color. Here it is on code pen: http://codepen.io/malikabee/pen/vEQZOv
$btn_color: #fff;
$btn_alpha: 1;
$btn_color_amount: 100%;
$color_funcs: (
'darken': darken($btn_color, $btn_color_amount),
'lighten': lighten($btn_color, $btn_color_amount),
'transparentize': transparentize($btn_color, $btn_alpha)
);
#mixin _btn_color($base_color, $amount, $hover){
background: $base_color;
a:hover,
a:focus{
#each $func_name, $color_func in $color_funcs{
#if($func_name == $hover){
$btn_color: $base_color;
$btn_color_amount: $amount;
background-color: $color_func;
}
}
}
}
.btn{
display: inline-block;
vertical-align: bottom;
text-align: center;
border-radius: 10px;
text-decoration: none;
}
.btn_blue{
#include _btn_color(#3c3c3c, 10%, 'darken');
}
Once you get past this block of code, the expressions don't exist anymore, only the value they evaluated to does:
$color_funcs: (
'darken': darken($btn_color, $btn_color_amount),
'lighten': lighten($btn_color, $btn_color_amount),
'transparentize': transparentize($btn_color, $btn_alpha)
);
Changing $btn_color after this point does nothing. Sass cannot to go back in time and re-run those expressions because they've already been evaluated using the original color (black).
What you can do instead is use the call function.
#mixin _btn_color($base_color, $amount, $func){
background: $base_color;
a:hover,
a:focus{
background-color: call($func, $base_color, $amount);
}
}
.btn_blue{
#include _btn_color(blue, 10%, 'darken');
color: white;
}

Isotope animating inserts from top-left of container

For my isotope container, whenever I insert a new item into the container... it initially appears in the top-left of the container (so in the position of the first item) and then it animates by moving down into place where it should go based on sorts.
Here is an example of what I would like to happen though: http://jsfiddle.net/aaairc/H4ZMV/5/. As you see in that example, the new item zooms in starting from the position that it is going to take within the container.
I haven't been able to replicate the issue I'm seeing locally on jsfiddle yet, but I thought someone might have an initial suggestion or point me to what in my jsfiddle example is actually enabling the insert to have the nice zoom in functionality. Is that just default? Something related to the CSS?
Also, not sure if this is relevant, but the container items of my isotope instance or all jpgs.
It had to do with how you specify the CSS. When I changed my CSS over to this it worked how I expected would like.
/**** Isotope CSS3 transitions ****/
.isotope,
.isotope .isotope-item {
-webkit-transition-duration: 0.8s;
-moz-transition-duration: 0.8s;
transition-duration: 0.8s;
}
.isotope {
-webkit-transition-property: height, width;
-moz-transition-property: height, width;
transition-property: height, width;
}
.isotope .isotope-item {
-webkit-transition-property: -webkit-transform, opacity;
-moz-transition-property: -moz-transform, opacity;
transition-property: transform, opacity;
}
/**** disabling Isotope CSS3 transitions ****/
.isotope.no-transition,
.isotope.no-transition .isotope-item,
.isotope .isotope-item.no-transition {
-webkit-transition-duration: 0s;
-moz-transition-duration: 0s;
transition-duration: 0s;
}
/* End: Recommended Isotope styles */
/* disable CSS transitions for containers with infinite scrolling*/
.isotope.infinite-scrolling {
-webkit-transition: none;
-moz-transition: none;
transition: none;
}
This feature has been built into Isotope v1.4. See Metafizzy blog: Isotope v1.4 - refined inserting animation

css3 animation/transition/transform: How to make image grow?

I want to make my image grow to 1500px in height (and hopefully the width would just automatically re-size itself, if not, I could easily set it too)
I was using jquery .animate() but its just too choppy for my liking...
I know I can use the :
-webkit-transform: scale(2);
But I want it to be set to a specific size.. not just double or triple the image size.
Any help?
Thanks
You're looking for the -webkit-transition property for webkit. That allows you to specify two separate CSS rules (for instance, two classes) and then the type of transition to be applied when switching those rules.
In this case, you could simply define the start and end heights (I did both height and width in the example below) as well as defining -webkit-transition-property for the properties you want transitioned, and -webkit-transition-duration for the duration:
div {
height: 200px;
width: 200px;
-webkit-transition-property: height, width;
-webkit-transition-duration: 1s;
-moz-transition-property: height, width;
-moz-transition-duration: 1s;
transition-property: height, width;
transition-duration: 1s;
background: red;
}
div:hover {
width: 500px;
height: 500px;
-webkit-transition-property: height, width;
-webkit-transition-duration: 1s;
-moz-transition-property: height, width;
-moz-transition-duration: 1s;
transition-property: height, width;
transition-duration: 1s;
background: red;
}
Tested in Safari. The Safari team also posted a pretty good write-up on CSS Visual Effects.
However, I would also recommend having another look at jQuery, as the newer CSS3 stuff won't be fully compatible with versions of IE.

CSS3 Animation Question

How can I make a CSS3 Animation play to the end and then stop dead. I don't want it to return the elements being transformed back to their initial states.
Right now I'm using some javascript to add a class to the element after the animation's duration with the same properties as 100% in the animation.
This is possible with the "animation-fill-mode" defined as "forwards", at least in Webkit. I got this result with code like this:
#-webkit-keyframes test {
100% { background-color: #0000ff; }
}
a { background-color: #ff0000; }
a:hover { -webkit-animation: test 1s 1 ease forwards }
Note that specifying start color in 0% keyframe and end color in :hover was not necessary.
Of course, this code is Webkit specific. I haven't tried in other browsers with other vendor prefixes or with the general "animation" property.
put your end values in the main css class and the start values in the animation keyframes at 0%:
#keyframes test {
0% {
background-color: #ff0000; /* start value */
}
100% {
background-color: #0000ff;
}
}
a {
background-color: #ff0000; /* normal state */
}
a:hover {
animation-name: test;
animation-duration: 1s;
background-color: #ff0000; /* final state, after animation is finished */
}
In case this question is still open, I don't think this is possible using CSS3 animations as they're currently specified:
An animation does not affect the computed value before the application of the animation, before the animation delay has expired, and after the end of the animation.
However, you should be able to use CSS3 transitions for basic effects. There's a slide in the html5rocks.com presentation that shows how to do this. Here's the relevant [paraphrased] excerpt:
#box.left { margin-left: 0; }
#box.right { margin-left: 1000px; }
#box { -webkit-transition: margin-left 1s ease-in-out; }
// Run this to animate to the left
document.getElementById('box').className = 'left';
// Run this to animate to the right
document.getElementById('box').className = 'right';
animation-fill-mode: forwards
The animation-fill-mode CSS property specifies how a CSS animation should apply styles to its target before and after it is executing

Resources