返回列表 发布新帖
查看: 105|回复: 0

[代码技巧] 子比主题 – 精美弹窗样式美化

[复制链接]
SunJu_FaceMall
社区贡献

315

主题

190

回帖

1万

积分

等级头衔
Icon组别 : 管理员
Icon等级 :

积分成就
   钻石 : 524 颗
   贡献 : 1457 点
   金币 : 12 枚
Icon在线时间 : 1294 小时
Icon注册时间 : 2024-11-22
Icon最后登录 : 2025-10-29

荣誉勋章

会员LV.1会员LV.2会员LV.3会员LV.4会员LV.5会员LV.6会员LV.7会员LV.8会员LV.9会员LV.10

风云·优秀版主

飞流名人堂成员

1

实名认证 手机认证 vip vip-year FLLTCN发表于 2025-10-10 18:41:17 | 查看全部 |阅读模式 浙江金华

资源无需等待,交易就趁现在,全面资源整合网络大咖云集,让你轻松玩转互联网!

您需要 登录 才可以下载或查看,没有账号?立即注册

×
腾飞博客给大家写了一款不用子比主题的弹窗的一款弹窗,比较精美好看,腾飞把一些没有用的都去掉了,这个弹窗就单独用的JS来写的,没有用多余的,CSS代码也放到JS里面了,很实用,喜欢的自行部署吧!

tengfei_down (15).webp


代码部署


定位:子比主题–>>自定义javascript代码,将代码放到里面,自己修改一下里面的内容即可!
  1. jQuery(document).on('click', '.user-online-status .but', function () {
  2.     var $this = jQuery(this);
  3.     var $container = $this.closest('.user-online-status');
  4.     var status = $this.data('sta');
  5.     var nonce = $container.find('#user_online_status_nonce').val() ||
  6.                 window.user_online_status_nonce || '';

  7.     if ($this.data('processing')) return;

  8.     $this.data('processing', 1);

  9.     $container.find('.but').removeClass('active');
  10.     $this.addClass('active');

  11.     jQuery.ajax({
  12.         url: '/wp-admin/admin-ajax.php',
  13.         type: 'POST',
  14.         data: {
  15.             action: 'user_online_status_switch',
  16.             status: status,
  17.             nonce: nonce
  18.         },
  19.         success: function (response) {
  20.             if (response.success) {
  21.                 var user_id = window.current_user_id || '';
  22.                 if(user_id){
  23.                     jQuery('.online-status-dot.user-uid-' + user_id)
  24.                         .removeClass('online away busy offline')
  25.                         .addClass(status);
  26.                 }
  27.                 if (typeof notyf === 'function') {
  28.                     notyf(response.msg, 'success', 1000);
  29.                 }
  30.             } else {
  31.                 if (typeof notyf === 'function') {
  32.                     notyf(response.msg || '状态更新失败', "danger");
  33.                 }
  34.             }
  35.         },
  36.         error: function () {
  37.             if (typeof notyf === 'function') {
  38.                 notyf('网络请求异常');
  39.             }
  40.         },
  41.         complete: function () {
  42.             $this.data('processing', 0);
  43.         }
  44.     });
  45. });

  46. jQuery(document).on('click', "a[href*='action=logout']", function (e) {
  47.     var nonce = jQuery('#user_online_status_nonce').val() ||
  48.                 window.user_online_status_nonce || '';
  49.     var user_id = window.current_user_id || '';
  50.     if (user_id && nonce) {
  51.         e.preventDefault();
  52.         var logoutUrl = jQuery(this).attr('href');
  53.         jQuery.ajax({
  54.             url: '/wp-admin/admin-ajax.php',
  55.             type: 'POST',
  56.             data: {
  57.                 action: 'user_online_status_switch',
  58.                 status: 'offline',
  59.                 nonce: nonce
  60.             },
  61.             complete: function () {
  62.                 window.location.href = logoutUrl;
  63.             }
  64.         });
  65.     }
  66. });
  67. (function() {
  68.     function shouldShowAnnouncement() {
  69.         const lastShown = localStorage.getItem('announcementLastShown');
  70.         if (!lastShown) return true;
  71.         
  72.         try {
  73.             const oneDayLater = new Date(lastShown).getTime() + (24 * 60 * 60 * 1000);
  74.             return Date.now() > oneDayLater;
  75.         } catch (e) {
  76.             console.error('解析公告显示时间失败:', e);
  77.             return true;
  78.         }
  79.     }

  80.     if (!shouldShowAnnouncement()) {
  81.         console.log('24小时内已显示过公告,暂不显示');
  82.         return;
  83.     }

  84.     function disableBodyScroll() {
  85.         document.body.style.overflow = 'hidden';
  86.         document.body.style.paddingRight = getScrollbarWidth() + 'px';
  87.     }

  88.     function enableBodyScroll() {
  89.         document.body.style.overflow = '';
  90.         document.body.style.paddingRight = '';
  91.     }

  92.     function getScrollbarWidth() {
  93.         const outer = document.createElement('div');
  94.         outer.style.visibility = 'hidden';
  95.         outer.style.width = '100px';
  96.         outer.style.msOverflowStyle = 'scrollbar';
  97.         document.body.appendChild(outer);
  98.         
  99.         const widthNoScroll = outer.offsetWidth;
  100.         outer.style.overflow = 'scroll';
  101.         
  102.         const inner = document.createElement('div');
  103.         inner.style.width = '100%';
  104.         outer.appendChild(inner);
  105.         
  106.         const widthWithScroll = inner.offsetWidth;
  107.         outer.parentNode.removeChild(outer);
  108.         
  109.         return widthNoScroll - widthWithScroll;
  110.     }
  111.     function injectStyles() {
  112.         const style = document.createElement('style');
  113.         style.textContent = `
  114. .one-popup-windows{display:block}.modal-backdrop.fade.in{z-index:151}.one-popup-content{position:fixed;top:50%;left:50%;z-index:152;width:480px;border-radius:10px;background-color:#fff;background-image:url(https://img.alicdn.com/imgextra/i4/2210123621994/O1CN01F0Ts8N1QbIqYOET57_!!2210123621994.png),url(https://img.alicdn.com/imgextra/i2/2210123621994/O1CN01wbq9a41QbIqZK6cK3_!!2210123621994.png);background-position:0 0,100% 280px;background-repeat:no-repeat;-webkit-box-shadow:0 0 80px rgb(0 0 0 / 25%);box-shadow:0 0 80px rgb(0 0 0 / 25%);opacity:1;-webkit-transform:translate(-50%,-50%);transform:translate(-50%,-50%);-ms-transform:translate(-50%,-50%)}.one-popup-header{margin-top:45px;color:#222;text-align:center;font-weight:700;font-size:28px}.one-popup-body{overflow-x:hidden;overflow-y:auto;margin:35px auto 40px;height:220px;padding:0 35px;scrollbar-width:none;-ms-overflow-style:none}.one-popup-body::-webkit-scrollbar{display:none}.one-popup-body p{margin-bottom:10px;color:#777;text-align:justify;font-weight:400;font-size:13px;line-height:22px;word-break:break-all}.one-popup-body p:last-child{margin-bottom:0}.one-popup-body p a{color:var(--one-popup-link_color)}.one-popup-btn-group{display:flex;justify-content:center;margin-bottom:2rem;gap:12px}.one-popup-btn{height:46px;border-radius:8px;font-size:15px;font-weight:600;cursor:pointer;transition:all 0.3s ease;border:none;outline:none;padding:0 20px;display:inline-flex;align-items:center;justify-content:center;box-shadow:0 2px 5px rgba(0,0,0,0.05)}.one-popup-btn:hover{transform:translateY(-2px);box-shadow:0 4px 12px rgba(0,0,0,0.1)}.one-popup-btn:active{transform:translateY(0);box-shadow:0 2px 3px rgba(0,0,0,0.08)}.one-popup-btn-not-show{background:linear-gradient(135deg,#5b96f7,#3a78e0);color:#ffffff;min-width:120px}.one-popup-btn-not-show:hover{background:linear-gradient(135deg,#4a85e6,#2d67d0)}.one-popup-btn-no{background:linear-gradient(135deg,#f8f9fa,#e9ecef);color:#495057;min-width:100px}.one-popup-btn-no:hover{background:linear-gradient(135deg,#e9ecef,#dee2e6);color:#343a40}.one-popup-btn-yes{background:linear-gradient(135deg,#ff7a00,#ff5e00);color:#ffffff;min-width:180px}.one-popup-btn-yes:hover{background:linear-gradient(135deg,#e66b00,#e65200)}
  115.         `;
  116.         document.head.appendChild(style);
  117.     }

  118.     function closeAnnouncement(remember = false) {
  119.         const popup = document.getElementById('one-popup-windows');
  120.         const backdrop = document.querySelector('.modal-backdrop.fade.in');
  121.         
  122.         if (popup) {
  123.             popup.style.transition = 'opacity 0.3s ease, transform 0.3s ease';
  124.             popup.style.opacity = '0';
  125.             popup.style.transform = 'translate(-50%, -55%)';
  126.         }
  127.         
  128.         if (backdrop) {
  129.             backdrop.style.transition = 'opacity 0.3s ease';
  130.             backdrop.style.opacity = '0';
  131.         }
  132.         
  133.         setTimeout(() => {
  134.             if (popup) popup.remove();
  135.             if (backdrop) backdrop.remove();
  136.             enableBodyScroll();
  137.         }, 300);
  138.         
  139.         if (remember) {
  140.             localStorage.setItem('announcementLastShown', new Date().toISOString());
  141.         } else {
  142.             localStorage.removeItem('announcementLastShown');
  143.         }
  144.     }
  145.    
  146.     function createAnnouncement() {
  147.         disableBodyScroll();
  148.         
  149.         const backdrop = document.createElement('div');
  150.         backdrop.className = 'modal-backdrop fade in';
  151.         document.body.appendChild(backdrop);
  152.         
  153.         const popupContainer = document.createElement('div');
  154.         popupContainer.className = 'one-popup-windows';
  155.         popupContainer.id = 'one-popup-windows';

  156.         popupContainer.innerHTML = `
  157.             <div class="one-popup-content">
  158.                 <div class="one-popup-header">站内通告</div>
  159.                 <div class="one-popup-body">
  160.                     <p>腾飞博客专注于子比主题、教程、精品源码、软件基地分享</p>
  161.                     <p>1.丰富功能系统,扩展社区特色玩法,打造最好的互联网聚集圈子。</p>
  162.                     <p>2.准确信息真实交易,安全快捷又方便,让虚拟交易面对面。</p>
  163.                     <p>3.天上不会掉馅饼,话术骗术迷人心,切勿脱离平台线下交易,被骗与平台无关!</p>
  164.                     <p>官方Q群:<span><a href="/" target="_blank" style="color:#0000ff;">123456</a></span>钉推群:<span style="color:#dc3023;">123456</span>  站长QQ:<a href="https://wpa.qq.com/msgrd?v=3&uin=123456&site=ThemeBox&menu=yes" target="_blank" style="color:#00e079;">1234567</a></p>
  165.                 </div>
  166.                 <div class="one-popup-btn-group">
  167.                     <button class="one-popup-btn one-popup-btn-not-show">一天内不显示</button>
  168.                     <button class="one-popup-btn one-popup-btn-no">取消</button>
  169.                     <button class="one-popup-btn one-popup-btn-yes">我知道啦</button>
  170.                 </div>
  171.             </div>
  172.         `;

  173.         document.body.appendChild(popupContainer);
  174.         
  175.         const notShowBtn = popupContainer.querySelector('.one-popup-btn-not-show');
  176.         const cancelBtn = popupContainer.querySelector('.one-popup-btn-no');
  177.         const confirmBtn = popupContainer.querySelector('.one-popup-btn-yes');

  178.         if (notShowBtn) {
  179.             notShowBtn.addEventListener('click', () => closeAnnouncement(true));
  180.         }

  181.         if (cancelBtn) {
  182.             cancelBtn.addEventListener('click', () => closeAnnouncement(false));
  183.         }

  184.         if (confirmBtn) {
  185.             confirmBtn.addEventListener('click', () => closeAnnouncement(false));
  186.         }
  187.         
  188.         if (backdrop) {
  189.             backdrop.addEventListener('click', () => closeAnnouncement(false));
  190.         }

  191.         document.addEventListener('keydown', (e) => {
  192.             if (e.key === 'Escape') closeAnnouncement(false);
  193.         });
  194.     }

  195.     if (document.readyState === 'loading') {
  196.         document.addEventListener('DOMContentLoaded', () => {
  197.             injectStyles();
  198.             createAnnouncement();
  199.         });
  200.     } else {
  201.         injectStyles();
  202.         createAnnouncement();
  203.     }
  204. })();
复制代码



本帖被以下淘专辑推荐:

路虽远,行则将至;事虽难,做则必成。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

飞流广播+ 发布

系统消息:柒沐已经连续答对3道难题,逆天学霸谁与争锋?!#每日答题#
10-30 17:02
系统消息:柒沐已经连续答对10道难题,逆天学霸谁与争锋?!#每日答题#
10-09 09:07
系统消息:柒沐已经连续答对3道难题,逆天学霸谁与争锋?!#每日答题#
09-24 09:00
系统消息:柒沐已经连续答对3道难题,逆天学霸谁与争锋?!#每日答题#
09-11 11:40
系统消息:柒沐已经连续答对3道难题,逆天学霸谁与争锋?!#每日答题#
09-02 09:17
系统消息:柒沐已经连续答对3道难题,逆天学霸谁与争锋?!#每日答题#
08-27 08:56
系统消息:柒沐已经连续答对3道难题,逆天学霸谁与争锋?!#每日答题#
08-20 15:12
系统消息:柒沐已经连续答对3道难题,逆天学霸谁与争锋?!#每日答题#
08-03 10:22
系统消息:柒沐已经连续答对10道难题,逆天学霸谁与争锋?!#每日答题#
06-30 08:57
系统消息:柒沐已经连续答对3道难题,逆天学霸谁与争锋?!#每日答题#
06-18 09:14
系统消息:清风网络已经连续答对10道难题,逆天学霸谁与争锋?!#每日答题#
04-11 09:40
系统消息:清风网络已经连续答对3道难题,逆天学霸谁与争锋?!#每日答题#
04-10 09:31
系统消息:IXM77777已经连续答对3道难题,逆天学霸谁与争锋?!#每日答题#
04-09 13:44
系统消息:清风网络已经连续答对3道难题,逆天学霸谁与争锋?!#每日答题#
04-09 09:22
系统消息:柒沐已经连续答对10道难题,逆天学霸谁与争锋?!#每日答题#
04-09 08:52
系统消息:清风网络已经连续答对3道难题,逆天学霸谁与争锋?!#每日答题#
04-08 09:24
系统消息:柒沐已经连续答对3道难题,逆天学霸谁与争锋?!#每日答题#
04-07 09:02
系统消息:柒沐已经连续答对10道难题,逆天学霸谁与争锋?!#每日答题#
02-27 09:35
系统消息:柒沐已经连续答对3道难题,逆天学霸谁与争锋?!#每日答题#
02-26 09:06
系统消息:柒沐已经连续答对3道难题,逆天学霸谁与争锋?!#每日答题#
02-25 08:49
站内通告

提供资源交易、信息共享、靓号交流、技术变现、学习问答、兴趣娱乐等全面服务。

1.丰富功能系统,扩展社区特色玩法,打造最好的互联网聚集圈子。

2.准确信息真实交易,安全快捷又方便,让虚拟交易面对面。

3. 天上不会掉馅饼,话术骗术迷人心,切勿脱离平台线下交易,被骗与平台无关!

4. 欺诈骗钱,违规违法将视情受到警告&禁言&封号甚至检举至👮🏻‍♀️处理!

官方Q群:123129钉推群:BAYR2383 站长QQ:3220000000

投诉/建议/商务合作联系

fl@fllt.cn

严禁私下交易,被骗与本站无关。
违反交易细则,取证立查严惩。
  • 钉钉新帖推送群
  • 官方交流QQ群
  • 站长唯一微信号

👮曝光Ta|🧿小黑屋|📴手机页|飞流网 ( 渝ICP备2025054677号-1|电信增值许可 渝B2-20250789 )|网站地图

GMT+8, 2025-11-8 01:36 , Processed in 0.080078 second(s), 60 queries, MemCached On , Gzip On.

Based on XJ-TX X3.5 Licensed

飞流论坛 HanAnalytics icp Astro vhAstro-Theme

关灯 在本版发帖
扫一扫添加微信客服
QQ客服返回顶部
快速回复 返回顶部 返回列表