当前位置: 首页 > news >正文

给WordPress网站添加返回顶部按钮

给WordPress网站底部添加一个按钮,点它就可以现实快速返回到顶部。有两种方法可以现实,一种是通过安装相关插件来实现。另外一种方式就是以纯属代码的方式来实现。

给WordPress网站底部添加一个按钮,点它就可以现实快速返回到顶部。有两种方法可以现实,一种是通过安装相关插件来实现。另外一种方式就是以纯属代码的方式来实现。
不废话,直接上代码。
1、将下面这段代码添加加到footer.php</footer>标签后

<a href="#" class="back-to-top"><i class="fa fa-angle-up"></i></a>


2、将下面这段JS代码添加到js/customer.js中

$(window).scroll(function(){
      if ($(this).scrollTop() > 100) {
          $('.back-to-top').addClass('fixed-back-to-top');
      } else {
          $('.back-to-top').removeClass('fixed-back-to-top');
      }
  });


3、将下面这段CSS代码添加到css/theme.css中

.back-to-top {
    color:#fff;
}
.fixed-back-to-top {
  position: fixed;
  right: 15px;
  bottom: 15px;
  z-index: 1150;
  background: #ff6600; 
  color: #fff; 
  width: 50px; 
  height: 50px; 
  text-align: center; 
  border-radius:50%;
}
.fixed-back-to-top i {
  font-size:2rem; 
  line-height: 3rem; 
}
.fixed-back-to-top:hover {
    background: #333333; color: #fff; text-decoration: none;
}
.fixed-back-to-top:focus {
    color: #fff;
}
.active.fixed-back-to-top {
    transform: translateY(0px); -webkit-transform: translateY(0);
}
html.mobile .fixed-back-to-top {
    display: none !important;
}
html.tablet .fixed-back-to-top {
    display: none !important;
}
@media all and (min-width:480px)
{
.fixed-back-to-top {
    right: 40px; bottom: 40px;
}


到此大功告成,刷新网站,就可以看到,在网站的右下角会出现要添加的按钮图标了。

原文链接 https://www.mymoban.com/wp/3.html

http://www.lryc.cn/news/270498.html

相关文章:

  • App Inventor 2 接入短信服务,实现短信验证码功能
  • Linux环境grep搜索方法记录
  • C语言-破解密码
  • ffmpeg 解码文件时的时间戳问题
  • Java企业电子招投标系统源代码,支持二次开发,采用Spring cloud框架
  • [python]基于faster whisper实时语音识别语音转文本
  • 2023纠结中前行? 2024继续还是放下?
  • 原型链补充
  • 《Linux Nano命令详解:小而强大的文本编辑器》
  • 系列四、Eureka自我保护
  • C++回调函数-实操(二)
  • MySQL中常用的用户授权操作
  • LabVIEW开发智能火灾自动报警系统
  • Vagrant使用教程
  • 【Java】ThreadLocal原理与使用场景
  • 软件测试/测试开发丨Linux进阶命令(curl、jq)
  • 模式识别与机器学习-SVM(带软间隔的支持向量机)
  • CentOS 7 firewalld+ipset+定时任务防御ssh暴力破解——筑梦之路
  • ElasticSearch的RestClient结合Sniffer提高可用性
  • 【网络面试(2)】DNS原理-域名和IP地址的查询转换
  • 【PHP】函数array_intersect、array_diff:从数组中取出、去除指定的几个键值
  • 【华为机试】2023年真题B卷(python)-冠亚军排名-奖牌榜排名
  • MyBatisPlus之逻辑删除
  • 在macOS中搭建.NET MAUI开发环境
  • [NCTF 2022]calc
  • 【pandas_不重复项计数】
  • 菜鸟学习vue3笔记-vue hooks初体验
  • 81 使用DFS和BFS解机器人的运动范围
  • vue-springboot基于JavaWeb的家装一体化商城平台guptn
  • .NET进阶篇06-async异步、thread多线程2