css3作业1 旋转照片墙

"Hello World, Hello Blog"

Posted by wudimingwo on December 15, 2018

html

1
2
3
4
5
6
7
8
    <div class="wrapper">
      <div>1</div>
      <div>2</div>
      <div>3</div>
      <div>4</div>
      <div>5</div>
      <div>6</div>
    </div>

main.scss 最近刚开始练习scss, 虽然还不太会用,但确实方便很多

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
@import "./new_file.scss";
:root{
    width: 100%;
    height: 100%;
}
body{
    margin: 0;
    padding: 0;
    @include base-size(100%,100%, #323232);
    position: relative;
    perspective: 1000px;
    
    .wrapper{
        transform-style: preserve-3d;
        transition: transform 10s;
        width: 400px;
        height: 250px;
        position: absolute;
        left: 50%;
        top: 50%;
        margin-left: -250px;
        margin-top: -125px;
        div{
            position: absolute;
            width: 100%;
            height: 100%;
            background-color: #F08080;
            background-size: cover;
            background-repeat: no-repeat;
        }
        @for $i from 1 through 6 {
            div:nth-of-type(#{$i}){
                background-image: url(../img/#{$i}.jpg);
                transform: rotateY(#{($i - 1) * 60}deg) translateZ(400px);
            }// 这里这种运算感觉就能省很多代码
        }
        &:hover{
            transform: rotateY(720deg);
        }
    }
}

new_file.scss

1
2
3
4
5
6
@mixin base-size($width,$height,$color){
    width: $width;
    height: $height;
    border: 1px solid black;    
    background-color: $color;
}