标签: Js功能

  • 给B2添加私信弹窗

    给B2添加私信弹窗

    简介

    这是一个用于B2主题的私信弹窗功能,由于默认私信消息提醒感知太弱,看到别人给自己发的私信时,基本都过了一俩月了!!!

    之前折腾了几次简单的,这次干脆弄的像样点。

    提前声明:本文为原创小功能,界面来自codepen.io修改,转载请注明来源。

    原理

    通过给私信标签添加固定样式,从而进行监控指定内容。

    如果成立,就弹窗,不成立就隐藏。

    代码使用方法如下 – 请按步骤修改代码

     

    第一步:在子主题functions.php中添加如下代码,加载指定文件

    // 修改私信提醒443行
    require_once get_stylesheet_directory() . '/Modules/Templates/Footer.php';

    第二步:根据上方文件路径,打开文件,找到以下代码

    如果你子主题没有对应文件,在子主题中创建对应路径文件夹,然后去父主题复制对应文件到子主题内。

    给代码中的有新私信私信列表,前方的span样式中,添加额外样式名diy-sixin

    详情看下方代码,也可以直接复制替换。

    <?php if($aside_dmsg && !$audit) { ?>
        <div :class="['bar-item',{'active':showType.dmsg}]" @click="show('dmsg','<?php echo $dmsg_url;?>')">
              <b v-show="dmsg.count" class="bar-mark"></b>
              <?php echo b2_get_icon('b2-mail-send-line'); ?>
              <span class="bar-item-desc diy-sixin" v-if="dmsg.count"><?php echo __('有新私信','b2'); ?></span>
              <span class="bar-item-desc diy-sixin" v-else><?php echo __('私信列表','b2'); ?></span>
        </div>
    <?php } ?>

    第三步:在footer.php中,添加以下代码,添加位置如图

    给B2添加私信弹窗

    代码如下:

    [content_hide]

    <!--私信消息提醒-->
            <div id="container-sixin">
              <div id="success-box-sixin">
                <div class="dot-sixin"></div><div class="dot-sixin two-sixin"></div>
                <div class="face-sixin">
                  <div class="eye-sixin"></div>
                  <div class="eye-sixin right-sixin"></div>
                  <div class="mouth-sixin happy-sixin"></div>
                </div>
                <div class="shadow scale-sixin"></div>
                <div class="message-sixin">
                  <h1 class="alert-sixin">您有一条新私信</h1>
                  <p>请前往查看</p>
                </div>
                <button class="button-box-sixin">
                  <a href="/directmessage" target="_blank" id="view-message-link-sixin">查看私信</a>
                </button>
              </div>
            </div>
    
            <script>
              document.addEventListener('DOMContentLoaded', function() {
                const container = document.getElementById('container-sixin');
                const messageIndicator = document.querySelector('.diy-sixin');
                const viewMessageLink = document.getElementById('view-message-link-sixin');
            
                function showNotification() {
                  if (container) { // 确保元素存在
                    container.style.bottom = '0';
                  }
                }
            
                function hideNotification() {
                  if (container) { // 确保元素存在
                    container.style.bottom = '-300px';
                  }
                }
            
                function checkMessageIndicator() {
                  if (messageIndicator && container) { // 确保两个元素都存在
                    if (messageIndicator.textContent.trim() === '有新私信') {
                      showNotification();
                    } else if (messageIndicator.textContent.trim() === '私信列表') {
                      hideNotification();
                    } else {
                      hideNotification(); // 默认隐藏
                    }
                  }
                }
            
                // 初始加载时检查
                checkMessageIndicator();
            
                // 监听 .diy-sixin 内容的变化
                const observer = new MutationObserver(checkMessageIndicator);
                if (messageIndicator) {
                  observer.observe(messageIndicator, { childList: true, characterData: true, subtree: true });
                }
            
                // 点击查看私信按钮后隐藏通知
                if (viewMessageLink && container) {
                  viewMessageLink.addEventListener('click', hideNotification);
                }
              });
            </script>
            <!--私信消息提醒结束-->

     

    第四步:在style.css中,添加样式代码

    由于代码中兼容了手机端(直接隐藏),如果不想兼容,可以自行找AI帮你取消兼容
    /**************************************** 私信消息弹窗开始 ********************************************/
    /*修改右侧侧边栏位置避免遮挡*/
    
    .bar-middle {
        bottom: 30%!important;
    }
    
    /* 桌面端样式 */
      @media (min-width: 769px) {
        #container-sixin {
          position: fixed;
          right: 20px;
          bottom: -300px;
          margin: 0;
          overflow: hidden;
          z-index: 999;
          width: 200px;
          height: 250px;
          transition: bottom 0.5s ease-in-out;
          border-radius: 10px 10px 0 0;
          box-shadow: 0 -5px 15px rgba(0, 0, 0, 0.2);
        }
    
        .green-sixin {
          color: #4ec07d;
        }
    
        .alert-sixin {
          font-weight: 700;
          letter-spacing: 5px;
          font-size: 1em;
          padding-top: 5px;
          color: #fcfcfc;
          padding-bottom: 5px;
          text-transform: uppercase;
          margin: 0;
          text-align: center;
        }
    
        .message-sixin p {
          margin-top: 10px;
          font-size: 0.8em;
          font-weight: 400;
          color: #5e5e5e;
          letter-spacing: 1px;
          margin-bottom: 15px;
          text-align: center;
        }
    
        button-sixin,
        .dot-sixin {
          cursor: pointer;
        }
    
        #success-box-sixin {
          width: 200px;
          height: 250px;
          background: linear-gradient(to bottom, #b0db7d, #99dbb4);
          border-radius: 10px 10px 0 0;
          box-shadow: none;
          perspective: none;
          display: flex;
          flex-direction: column;
          align-items: center;
          justify-content: center;
        }
    
        .dot-sixin {
          width: 10px;
          height: 10px;
          background: #fcfcfc;
          border-radius: 50%;
          position: absolute;
          top: 15px;
          right: 20px;
        }
        .dot-sixin:hover {
          background: #c9c9c9;
        }
    
        .two-sixin {
          right: 45px;
          opacity: 0.5;
        }
    
        .face-sixin {
          width: 50px;
          height: 50px;
          background: #fcfcfc;
          border-radius: 50%;
          border: 2px solid #777777;
          z-index: 2;
          animation: bounce-sixin 1s ease-in infinite;
          margin-bottom: 15px;
        }
    
        .eye-sixin {
          position: absolute;
          width: 8px;
          height: 8px;
          background: #777777;
          border-radius: 50%;
          top: 35%;
          left: 25%;
        }
    
        .right-sixin {
          left: 65%;
        }
    
        .mouth-sixin {
          position: absolute;
          top: 55%;
          left: 40%;
          width: 12px;
          height: 12px;
          border-radius: 50%;
        }
    
        .happy-sixin {
          border: 2px solid;
          border-color: transparent #777777 #777777 transparent;
          transform: rotate(45deg);
          width: 15px;
          height: 15px;
          top: 50%;
          left: 38%;
        }
    
        .shadow {
        position: absolute;
        width: 26%;
        height: 3%;
        opacity: 0.5;
        background: #777777;
        left: 37%;
        top: 34%;
        border-radius: 50%;
        z-index: 1;
        animation: scale-sixin 1s ease-in infinite; /* 缩放动画 */
      }
      
      #view-message-link-sixin{
          width: 100%;
        height: 100%;
        position: absolute;
        text-align: center;
        line-height: 40px;
      }
      
      
        .shadow-sixin {
          display: none;
        }
    
        .message-sixin {
          text-align: center;
        }
    
        .button-box-sixin {
          background: #fcfcfc;
          width: 60%;
          height: 40px;
          border-radius: 20px;
          outline: 0;
          border: none;
          box-shadow: 2px 2px 10px rgba(119, 119, 119, 0.5);
          transition: all 0.3s ease-in-out;
          font-size: 1em;
          font-weight: bold;
          color: #4ec07d;
          display: flex;
          align-items: center;
          justify-content: center;
          cursor: pointer;
          text-decoration: none;
        }
        .button-box-sixin:hover {
          background: #efefef;
          transform: scale(1.02);
        }
    
        @keyframes bounce-sixin {
      50% {
        transform: translateY(-5px);
      }
    }
    
    @keyframes scale-sixin {
      50% {
        transform: scale(0.95);
      }
    }
    
      /* 移动端和平板样式 - 隐藏提示和容器 */
      @media (max-width: 768px) {
        .diy-sixin,
        #container-sixin {
          display: none !important;
        }
      }
    
      .diy-sixin {
        display: none; /* 初始时隐藏该元素 */
      }
    
    /**************************************** 私信消息弹窗结束 ********************************************/

    [/content_hide]

    具体界面样式、显示文字等都可以自行修改,会css就行了。
    同时此功能也可以用在顶部的消息上,这要你自己改改了,不过消息里基本都是些积分通知,感觉无关紧要了。
    比如可以添加判断,把你有一条新私信那里改为变量,通过判断修改为消息或私信。
    动态修改按钮地址,这个比较麻烦了,感觉没什么必要,你可以自己折腾折腾
  • 网站滚动进度条

    网站滚动进度条

    代码介绍

    它会在页面顶部显示一个进度条,当用户滚动页面时,进度条的长度会根据用户的滚动位置动态变化。

    注意:当你的页面长度不够时,这个进度条会有一个默认的长度,这与你右侧的滚动条长度基本一致。

    视频介绍


    [content_hide]

    📦 资源下载
    🔐 提取码:
    OL4FS



    立即下载

    [/content_hide]

  • 网站加载进度条

    网站加载进度条

    代码效果

    这个代码实现了页面加载进度条功能。其核心目的是在页面加载过程中显示一个进度条,以向用户展示页面加载的进度情况,让用户在等待加载完成时能够得到视觉上的反馈。

    视频介绍


    [content_hide]

    📦 资源下载
    🔐 提取码:
    Dj3AP



    立即下载

    [/content_hide]

  • 给网站添加一个上吊猫

    给网站添加一个上吊猫

    代码效果

    这是一个返回顶部按钮的功能,被魔改为了一只小猫。

    当用户滚动到页面底部时,点击小猫,即可自动返回到页面顶部

    视频介绍


    [content_hide]

    📦 资源下载
    🔐 提取码:
    n3FwO



    立即下载

    [/content_hide]

  • 一个文件让你的网页丝滑起来

    文件介绍如果你觉得我的网站滚动起来滑滑的,那么就归功于这个JS文件了。由于是古老备份,已经不记得这个文件的出处了,知道的小伙伴可以告知我一下。

    使用方法

    全局引用

    这是一个js文件,应当整站引用。比如放到header.php、footer.php中,全局引用。js文件的引用方法不再多说

    functions.php中全局引用,详细说明可查看下方文章

    [b2_insert_post id=”104″]

    function.php相关代码,将/diy/sihua.js修改为你的文件路径

    // 自定义全局输出文件****************************************
    function bber_css_js() {
        // 输出其他路径的 CSS 文件
        //wp_enqueue_style( '唯一标识符', get_stylesheet_directory_uri() . '文件路径', array(), '1.0' );
    
        // 输出其他路径的 JS 文件
        wp_enqueue_script( 'sihua', get_stylesheet_directory_uri() . '/diy/sihua.js', array(), '1.0', true );
    }
    
    add_action( 'wp_enqueue_scripts', 'bber_css_js' );
    
    

     
    [content_hide]

    📦 资源下载
    🔐 提取码:
    hrIrn



    立即下载

    [/content_hide]