Skip to content

Instantly share code, notes, and snippets.

@CodeMyUI
Forked from anonymous/animation - flip.markdown
Created January 11, 2016 08:58
Show Gist options
  • Select an option

  • Save CodeMyUI/8b3505fe4b070f3093df to your computer and use it in GitHub Desktop.

Select an option

Save CodeMyUI/8b3505fe4b070f3093df to your computer and use it in GitHub Desktop.
animation - flip
<div id="app">
<p class="m-flip js-flip" style="font-size: 60px; font-family:Abel;">
<span class="m-flip_item">ABCDEFGHIJKLMNOPQRSTUVWXYZ</span>
<span class="m-flip_item">ABCDEFGHIJKLMNOPQRSTUVWXYZ</span>
</p>
<p class="m-flip js-flip" style="font-size: 30px; font-family:'Permanent Marker', cursive;">
<span class="m-flip_item">ABCDEFGHIJKL<br>MNOPQRSTUVWXYZ</span>
<span class="m-flip_item">あいうえおかきくけこさし<br>すせそたちつてとなにぬねのはひふへほ</span>
</p>
<p class="m-flip js-flip" style="font-size: 10px;">
<span class="m-flip_item">あいうえおかきくけこさしすせそたちつてとなにぬねのはひふへほ</span>
<span class="m-flip_item">ABCDEFGHIJKLMNOPQRSTUVWXYZ</span>
</p>
</div>
(function($){
$.fn.flip = function(options){
var options = $.extend({
targetClass: '.m-flip_item'
}, options);
return this.each(function(){
console.log(this);
var $this = $(this),
$target = $this.find(options.targetClass);
$this
.on({
'init.flip': function(){
var targetFirst_height = $target.eq(0).height();
$this
.data('height', targetFirst_height)
.css({ height: targetFirst_height });
},
'mouseenter.flip': function(){
$target.css({ top: -$this.data('height') + 'px' });
},
'mouseleave.flip': function(){
$target.css({ top: 0 + 'px' });
}
})
.trigger('init.flip');
});
};
}(jQuery));
$(function(){
$('.js-flip').flip();
});
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
/* @IMPORT FONTS */
@import url(https://fonts.googleapis.com/css?family=Abel);
@import url(https://fonts.googleapis.com/css?family=Permanent+Marker);
/* BASE */
body{
background-color: #000;
color: #fff;
font-family: sans-serif;
line-height: 1;
font-smoothing: antialiased;
}
#app{
width: 80%;
margin: 0 auto;
padding: 5% 0 0;
}
/**
* ANIMATION - FLIP
*/
.m-flip{
overflow: hidden;
cursor: pointer;
}
.m-flip_item{
display: block;
position: relative;
top: 0;
transition: top .2s ease-out 0s;
&:nth-child(1){
color: #666;
}
}
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment