html 照片墙 - CSS + GSAP
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了html 照片墙 - CSS + GSAP相关的知识,希望对你有一定的参考价值。
@import url('https://fonts.googleapis.com/css?family=Saira+Extra+Condensed');
@import url('https://fonts.googleapis.com/css?family=Inconsolata');
.wall {
width: 100%;
height: 100%;
position: absolute;
left: 50%;
top: 50%;
transform: translateX(-50%) translateY(-50%);
overflow: hidden;
box-sizing: border-box;
background-color: #000;
min-height: 800px;
}
.wall div {
box-sizing: border-box;
}
.wall .slide {
position: absolute;
left: 0%;
top: 0%;
height: 100%;
width: 100%;
overflow: hidden;
cursor: pointer;
background-color: #333;
opacity: 0;
}
.wall .slide .image {
position: absolute;
left: 50%;
top: 50%;
height: 100%;
width: 100%;
transform: translateX(-50%) translateY(-50%);
}
.wall .slide .image .image-in {
position: absolute;
left: 50%;
top: 50%;
height: 105%;
width: 105%;
background-size: cover;
background-position: center;
transform: translateX(-50%) translateY(-50%);
}
.wall .slide .image .image-in.image2 {
filter: gray; /* IE6-9 */
-webkit-filter: grayscale(1); /* Google Chrome, Safari 6+ & Opera 15+ */
filter: grayscale(1);
transition: opacity 0.5s;
}
.wall .slide:hover .image-in.image2 {
opacity: 0;
}
.wall .slide:nth-child(1) .image .image-in {
background-image: url(https://preview.animatedcreativity.com/images/photowall/new/image1-21.jpg);
}
.wall .slide:nth-child(2) .image .image-in {
background-image: url(https://preview.animatedcreativity.com/images/photowall/new/image2.jpg);
}
.wall .slide:nth-child(3) .image .image-in {
background-image: url(https://preview.animatedcreativity.com/images/photowall/new/image3-1.jpg);
}
.wall .slide:nth-child(4) .image div {
background-image: url(https://preview.animatedcreativity.com/images/photowall/new/image4-1.jpg);
}
.wall .slide:nth-child(5) .image .image-in {
background-image: url(https://preview.animatedcreativity.com/images/photowall/new/image5-1.jpg);
}
.wall .slide:nth-child(6) .image .image-in {
background-image: url(https://preview.animatedcreativity.com/images/photowall/new/image6-1.jpg);
}
.wall .slide:nth-child(7) .image .image-in {
background-image: url(https://preview.animatedcreativity.com/images/photowall/new/image7.jpg);
}
.wall .slide:nth-child(8) .image .image-in {
background-image: url(https://preview.animatedcreativity.com/images/photowall/new/image8.jpg);
}
.wall .slide:nth-child(9) .image .image-in {
background-image: url(https://preview.animatedcreativity.com/images/photowall/new/image9.jpg);
}
.wall .slide:nth-child(10) .image .image-in {
background-image: url(https://preview.animatedcreativity.com/images/photowall/new/image10-1.jpg);
}
.wall .slide:nth-child(11) .image .image-in {
background-image: url(https://preview.animatedcreativity.com/images/photowall/new/image11-1.jpg);
}
.wall .slide:nth-child(12) .image .image-in {
background-image: url(https://preview.animatedcreativity.com/images/photowall/new/image12-1.jpg);
}
.wall button {
position: absolute;
right: 5%;
top: 5%;
width: 10%;
height: 0%;
padding-bottom: 10%;
background: none;
border: none;
outline: none;
cursor: pointer;
opacity: 0.6;
transition: all 0.5s;
top: -30%;
right: -30%;
}
.wall button:before, .wall button:after {
content: "";
position: absolute;
left: 50%;
top: 50%;
width: 30%;
height: 100%;
background-color: #666;
transform: translateX(-50%) translateY(-50%) rotateZ(45deg);
border-radius: 100px;
}
.wall button:after {
transform: translateX(-50%) translateY(-50%) rotateZ(-45deg);
}
.wall button:hover {
opacity: 1;
}
.wall .image .preloader {
position: absolute;
width: 10%;
height: 0%;
padding-bottom: 10%;
left: 50%;
top: 50%;
transform: translateX(-50%) translateY(-50%);
}
.wall .image .preloader div {
position: absolute;
width: 100%;
height: 100%;
left: 50%;
transform: translateX(-50%) translateY(-50%);
overflow: hidden;
animation: animatePreloader 1s infinite linear;
transform-origin: 50% 100%;
}
.wall .image .preloader div:before {
content: "";
position: absolute;
width: 100%;
height: 100%;
left: 50%;
top: 50%;
transform: translateX(-50%);
border: 3px solid #ccc;
border-radius: 50%;
box-sizing: border-box;
}
.wall .image .preloader div:nth-child(2) {
width: 60%;
height: 60%;
top: 20%;
animation: animatePreloader 0.5s infinite linear;
}
@keyframes animatePreloader {
0% {
transform: translateX(-50%) translateY(-50%) rotateZ(0deg);
}
100% {
transform: translateX(-50%) translateY(-50%) rotateZ(360deg);
}
}
.wall .slide .text {
position: absolute;
color: #333;
box-sizing: border-box;
padding: 20px;
margin: 20px;
width: 50%;
background-color: rgba(255, 255, 255, 0.2);
opacity: 0;
transition: background-color 0.5s;
}
.wall .slide .text:hover {
background-color: rgba(255, 255, 255, 1);
}
.wall .slide .text h1, .wall .slide .text div {
margin: 0px;
padding: 0px;
}
.wall .slide .text h1 {
text-transform: uppercase;
font-family: 'Saira Extra Condensed', sans-serif;
}
.wall .slide .text div {
margin-top: 20px;
font-family: 'Inconsolata', monospace;
}
.wall .hint {
position: absolute;
left: 50%;
bottom: 20px;
color: #333;
background-color: rgba(255, 255, 255, 0.7);
padding: 10px;
box-sizing: border-box;
transform: translateX(-50%);
font-family: 'Inconsolata', monospace;
opacity: 0.1;
transition: all 0.5s;
cursor: pointer;
}
.wall .hint:hover {
opacity: 1;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/1.20.2/TweenMax.min.js"></script>
var acAnimated = {currentSlide: 0};
acAnimated.randomNumber = function(min, max) {
var num = min + Math.floor(Math.random() * (max - (min - 1)));
return num;
}
acAnimated.Wall = function(wall) {
var rows = wall.getAttribute("rows");
var columns = wall.getAttribute("columns");
var slides = wall.querySelectorAll(".slide");
var closeButton = wall.querySelector("button.close-button");
var timeline = new TimelineMax({});
var currentRow = 0;
var currentColumn = 0;
for (var i=0; i<=slides.length-1; i++) {
var slide = slides[i];
slide.style.width = (100 / columns) + "%";
slide.style.height = (100 / rows) + "%";
slide.column = currentColumn;
slide.row = currentRow;
slide.className = slide.className + " slide_row_" + String(slide.row) + "_column_" + String(slide.column);
slide.style.left = currentColumn * (100 / columns) + "%";
slide.style.top = currentRow * (100 / rows) + "%";
currentColumn += 1;
if (currentColumn >= columns) {
currentColumn = 0;
currentRow += 1;
}
timeline
.add("slide_" + String(i + 1), acAnimated.randomNumber(0, 5) / 10)
.to(slide, 0.5, {opacity: 1}, "slide_" + String(i + 1));
slide.onclick = function() {
var text = this.querySelector(".text");
var timeline = new TimelineMax({});
timeline
.add("play_timeline", 0)
.to(text, 0.5, {opacity: 1}, "play_timeline");
//left
for (var i=0; i<=this.column-1; i++) {
var _slide = wall.querySelector(".slide_row_" + String(this.row) + "_column_" + String(i));
timeline
.to(_slide, 0.5, {left: String(0 - ((100 / columns) * (this.column - i))) + "%"}, "play_timeline");
}
//right
for (var i=this.column+1; i<=columns-1; i++) {
var _slide = wall.querySelector(".slide_row_" + String(this.row) + "_column_" + String(i));
timeline
.to(_slide, 0.5, {left: String(100 + ((100 / columns) * ((i - this.column) - 1))) + "%"}, "play_timeline");
}
//top
for (var i=0; i<=this.row-1; i++) {
for (var c=0; c<=columns-1; c++) {
var _slide = wall.querySelector(".slide_row_" + String(i) + "_column_" + String(c));
timeline
.to(_slide, 0.5, {top: String(0 - ((100 / rows) * (this.row - i))) + "%"}, "play_timeline");
}
}
//bottom
for (var i=this.row+1; i<=rows-1; i++) {
for (var c=0; c<=columns-1; c++) {
var _slide = wall.querySelector(".slide_row_" + String(i) + "_column_" + String(c));
timeline
.to(_slide, 0.5, {top: String(100 + ((100 / rows) * ((i - this.row) - 1))) + "%"}, "play_timeline");
}
}
timeline
.to(closeButton, 0.5, {top: "5%", right: "5%"}, "play_timeline")
.to(this, 0.5, {left: "0%", top: "0%", width: "100%", height: "100%"}, "play_timeline");
closeButton.onclick = function() {
var timeline = new TimelineMax({});
timeline
.add("play_timeline", 0)
.to(text, 0.5, {opacity: 0}, "play_timeline");
for (var i=0; i<=slides.length-1; i++) {
var _slide = slides[i];
timeline
.to(_slide, 0.5, {top: String((100 / rows) * _slide.row) + "%", left: String((100 / columns) * _slide.column) + "%", width: String(100 / columns) + "%", height: String(100 / rows) + "%"}, "play_timeline");
}
timeline
.to(this, 0.5, {top: "-30%", right: "-30%"}, "play_timeline");
}
}
}
}
acAnimated.Wall(document.body.querySelector(".wall"));
Photo Wall - CSS+GSAP
---------------------
A beautiful & simple photo gallery. You can add as many rows and columns as you want and animation will adapt accordingly. Please view in full page size because min-height is set.
Images by unsplash.com & pexels.com
A [Pen](https://codepen.io/animatedcreativity/pen/NaBxWY) by [Animated Creativity](https://codepen.io/animatedcreativity) on [CodePen](https://codepen.io).
[License](https://codepen.io/animatedcreativity/pen/NaBxWY/license).
<div class="wall" rows="2" columns="3">
<div class="slide">
<div class="image"><div class="preloader"><div></div><div></div></div><div class="image-in image1"></div><div class="image-in image2"></div></div>
<div class="text">
<h1>Fusce tincidunt lacus non neque hendrerit</h1>
<div>Nam imperdiet aliquet efficitur. Morbi ipsum libero, viverra a varius at, sagittis consectetur nisl. Donec mauris justo, aliquam dignissim sagittis id, porttitor vel velit. Sed aliquam gravida nibh vitae molestie. Aliquam eros sapien, luctus ut suscipit in, placerat eu ligula.</div>
</div>
</div>
<div class="slide">
<div class="image"><div class="preloader"><div></div><div></div></div><div class="image-in image1"></div><div class="image-in image2"></div></div>
<div class="text">
<h1>Curabitur suscipit neque</h1>
<div>Cras ultricies metus non dignissim sagittis. Nunc gravida at nisl sit amet aliquet. Vivamus lobortis nibh at varius dictum. Suspendisse pulvinar sem in varius rhoncus. Sed iaculis congue vulputate. Integer vel blandit ex, nec finibus ipsum.</div>
</div>
</div>
<div class="slide">
<div class="image"><div class="preloader"><div></div><div></div></div><div class="image-in image1"></div><div class="image-in image2"></div></div>
<div class="text">
<h1>Integer tristique purus vitae</h1>
<div>Nulla facilisi. In hac habitasse platea dictumst. Sed et lobortis magna, sed sollicitudin lorem. Etiam ut rutrum risus. Quisque sed eros iaculis nisi euismod vehicula. Nulla ac arcu feugiat, iaculis dolor sit amet, pretium justo.</div>
</div>
</div>
<div class="slide">
<div class="image"><div class="preloader"><div></div><div></div></div><div class="image-in image1"></div><div class="image-in image2"></div></div>
<div class="text">
<h1>Cras in orci at nisl rutrum</h1>
<div>Nullam imperdiet laoreet vestibulum. Sed consequat nisi ut auctor luctus. Pellentesque id lacus id purus finibus vestibulum sed dignissim mi. Vestibulum egestas pharetra arcu et elementum. Phasellus suscipit sem et elit egestas vestibulum.</div>
</div>
</div>
<div class="slide">
<div class="image"><div class="preloader"><div></div><div></div></div><div class="image-in image1"></div><div class="image-in image2"></div></div>
<div class="text">
<h1>Pellentesque varius diam</h1>
<div>Ut ultrices magna in ipsum scelerisque pellentesque. Donec vel tempus tortor. Integer id consectetur mi, quis auctor enim. Aliquam vehicula nisi at orci pulvinar, ac condimentum libero blandit.</div>
</div>
</div>
<div class="slide">
<div class="image"><div class="preloader"><div></div><div></div></div><div class="image-in image1"></div><div class="image-in image2"></div></div>
<div class="text">
<h1>Maecenas iaculis arcu</h1>
<div>Ut quis consectetur odio. Nam suscipit nibh ut euismod pharetra. Aliquam eleifend, urna ut vulputate fermentum, metus tortor elementum nisi, vel blandit mi arcu dapibus purus. Sed et urna et erat rhoncus imperdiet.</div>
</div>
</div>
<div class="hint">You can set as many rows and columns as you want.</div>
<button class="close-button"></button>
</div>
以上是关于html 照片墙 - CSS + GSAP的主要内容,如果未能解决你的问题,请参考以下文章
HTML+CSS 旋转照片墙!源代码(简易动画干货快收藏!!)