当前位置:   article > 正文

HEXO Next 小魔方(个性化回到顶部)_next怎么把回到顶部按钮换位置

next怎么把回到顶部按钮换位置
实现的效果

在这里插入图片描述

具体步骤如下

1.添加实现代码

在/themes/next/layout/ _custom/ 路径下新建cube-hollow.swig文件

添加如下内容

<style>
  /*最外层容器样式*/
  .wrap {
    width: 0px;
    height: 0px;
    /*margin: 80px;*/
    /*position: relative;*/
    position: fixed;
      /*显示位置*/
    bottom: 80px;
    right: 80px;
    z-index: 999;
  }

  /*包裹所有容器样式*/
  .cube {
    width: 0px;
    height: 0px;
    margin: 0 auto;
    -webkit-transform-style: preserve-3d;
    transform-style: preserve-3d;
    transform: rotateX(-30deg) rotateY(-80deg);
    animation: rotate linear 10s infinite;
  }

  @-webkit-keyframes rotate {
    from {
      transform: rotateX(0deg) rotateY(0deg);
    }
    to {
      transform: rotateX(360deg) rotateY(360deg);
    }
  }

  .cube div {
    position: absolute;
    /*显示大小*/
    width: 50px;
    height: 50px;
    opacity: 0.8;
    transition: all .4s;
  }

  /*定义所有图片样式*/
  .pic {
    width: 50px;
    height: 50px;
  }

  .cube .out_front {
    transform: rotateY(0deg) translateZ(25px);
  }

  .cube .out_back {
    transform: translateZ(-25px) rotateY(180deg);
  }

  .cube .out_left {
    transform: rotateY(-90deg) translateZ(25px);
  }

  .cube .out_right {
    transform: rotateY(90deg) translateZ(25px);
  }

  .cube .out_top {
    transform: rotateX(90deg) translateZ(25px);
  }

  .cube .out_bottom {
    transform: rotateX(-90deg) translateZ(25px);
  }

  /*定义小正方体样式*/
  .cube span {
    display: block;
    width: 25px;
    height: 25px;
    position: absolute;
    top: 12px;
    left: 12px;
  }

  .cube .in_pic {
    width: 25px;
    height:25px;
  }

  .cube .in_front {
    transform: rotateY(0deg) translateZ(12px);
  }

  .cube .in_back {
    transform: translateZ(-12px) rotateY(180deg);
  }

  .cube .in_left {
    transform: rotateY(-90deg) translateZ(12px);
  }

  .cube .in_right {
    transform: rotateY(90deg) translateZ(12px);
  }

  .cube .in_top {
    transform: rotateX(90deg) translateZ(12px);
  }

  .cube .in_bottom {
    transform: rotateX(-90deg) translateZ(12px);
  }

  /*鼠标移入后样式*/
  .cube:hover .out_front {
    transform: rotateY(0deg) translateZ(50px);
  }

  .cube:hover .out_back {
    transform: translateZ(-50px) rotateY(180deg);
  }

  .cube:hover .out_left {
    transform: rotateY(-90deg) translateZ(50px);
  }

  .cube:hover .out_right {
    transform: rotateY(90deg) translateZ(50px);
  }

  .cube:hover .out_top {
    transform: rotateX(90deg) translateZ(50px);
  }

  .cube:hover .out_bottom {
    transform: rotateX(-90deg) translateZ(50px);
  }
</style>

<div class="wrap">

    <!--包裹所有元素的容器-->
    <div class="cube">
        <!--前面图片 -->
        <div class="out_front">
          <a onclick="back2top()">
              <img src="https://raw.githubusercontent.com/Joshua-li-yi/blog_images/master/images/first_1/5.jpg" class="pic" />
            </a>
        </div>
        <!--后面图片 -->
        <div class="out_back">
            <a onclick="back2top()">
              <img src="https://raw.githubusercontent.com/Joshua-li-yi/blog_images/master/images/first_1/5.jpg" class="pic" />
            </a>
        </div>
        <!--左面图片 -->
        <div class="out_left">
            <a onclick="back2top()">
              <img src="https://raw.githubusercontent.com/Joshua-li-yi/blog_images/master/images/first_1/5.jpg" class="pic" />
            </a>
        </div>
        <!--右面图片 -->
        <div class="out_right">
            <a onclick="back2top()">
                <img src="https://raw.githubusercontent.com/Joshua-li-yi/blog_images/master/images/first_1/5.jpg" class="pic" />
            </a>
        </div>
        <!--上面图片 -->
        <div class="out_top">
            <a onclick="back2top()">
                <img src="https://raw.githubusercontent.com/Joshua-li-yi/blog_images/master/images/first_1/5.jpg" class="pic" />
            </a>
        </div>
        <!--下面图片 -->
        <div class="out_bottom">
            <a onclick="back2top()">
                <img src="https://raw.githubusercontent.com/Joshua-li-yi/blog_images/master/images/first_1/5.jpg" class="pic" />
            </a>
        </div>

        <!--小正方体 -->
        <span class="in_front">
            <img src="https://raw.githubusercontent.com/Joshua-li-yi/blog_images/master/images/first_1/6.jpg" class="in_pic" />
        </span>
        <span class="in_back">
             <img src="https://raw.githubusercontent.com/Joshua-li-yi/blog_images/master/images/first_1/6.jpg" class="in_pic" />
        </span>
        <span class="in_left">
            <img src="https://raw.githubusercontent.com/Joshua-li-yi/blog_images/master/images/first_1/6.jpg" class="in_pic" />
        </span>
        <span class="in_right">
            <img src="https://raw.githubusercontent.com/Joshua-li-yi/blog_images/master/images/first_1/6.jpg" class="in_pic" />
        </span>
        <span class="in_top">
            <img src="https://raw.githubusercontent.com/Joshua-li-yi/blog_images/master/images/first_1/6.jpg" class="in_pic" />
        </span>
        <span class="in_bottom">
            <img src="https://raw.githubusercontent.com/Joshua-li-yi/blog_images/master/images/first_1/6.jpg" class="in_pic" />
        </span>
    </div>

</div>

<script>
  function back2top(){
    $('html, body').animate({scrollTop: 0}, 500);
  }
</script>
  • 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
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173
  • 174
  • 175
  • 176
  • 177
  • 178
  • 179
  • 180
  • 181
  • 182
  • 183
  • 184
  • 185
  • 186
  • 187
  • 188
  • 189
  • 190
  • 191
  • 192
  • 193
  • 194
  • 195
  • 196
  • 197
  • 198
  • 199
  • 200
  • 201
  • 202
  • 203
  • 204
  • 205
  • 206
  • 207

其中的照片最好放自己的鸭!

还有就是记得调整显示的位置哦!

这样基本小魔方的实现代码就写辽

2.调用

下面就是在个人主页中调用小魔方辽

  • 在 /themes/next/layout/_custom/custom.swig 文件中引入新建的文件

    <!-- 旋转魔方 -->
    {% if theme.cube.enable %}
       {% if theme.cube.type == "mini" %}
          {% include 'cube-mini.swig' %}
       {% elseif theme.cube.type == "hollow" %}
          {% include 'cube-hollow.swig' %}
       {% endif %}
    {% endif %}
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
  • 在主题next中的 _config.yml 中新添加以下动态配置项

    cube:
      enable: true
      type: hollow # mini | hollow
    
    • 1
    • 2
    • 3

这样子就好辽

最后再在gitbush中hexo g && hexo d就可

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/blog/article/detail/48914
推荐阅读
相关标签
  

闽ICP备14008679号