scroll-rotation
HTML
<div class="scroll-space">
<div class="rotation rotation-x blue">
X軸を基準に回転
</div>
<div class="rotation rotation-y pink">
Y軸を基準に回転
</div>
<div class="rotation rotation-clockwise yellow">
時計周りに回転
</div>
<div class="rotation rotation-counterclockwise green">
反時計周りに回転
</div>
</div>
SCSS
.scroll-space{
box-sizing: border-box;
padding-top: 300px;
height: 1600px;
color: #fff;
.blue{
background: #77BBCF;
width: 200px;
height: 200px;
padding: 30px;
margin: 0 auto 50px;
}
.pink{
background: #FFB4B4;
width: 200px;
height: 200px;
padding: 30px;
margin: 0 auto 50px;
}
.yellow{
background: #F8913C;
width: 200px;
height: 200px;
padding: 30px;
margin: 0 auto 50px;
}
.green{
background: #26AA5A;
width: 200px;
height: 200px;
padding: 30px;
margin: 0 auto 50px;
}
}
.rotation {
transition: all 1.0s;
opacity: 0;
&.rotation-x{
transform: rotateX(180deg);
}
&.rotation-y{
transform: rotateY(180deg);
}
&.rotation-clockwise{
transform: rotate(-170deg);
}
&.rotation-counterclockwise{
transform: rotate(170deg);
}
&.scrollin{
transform: translate(0, 0)!important;
opacity: 1!important;
}
}
JavaScript
$(window).scroll(function (){
$('.rotation').each(function(){
var elemPos = $(this).offset().top,
scroll = $(window).scrollTop(),
windowHeight = $(window).height();
if (scroll > elemPos - windowHeight + 150){
$(this).addClass('scrollin');
}
});
});