吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 251|回复: 4
收起左侧

[求助] js脚本如何为函数添加一个参数,让其能在调用的时候控制选择style?

[复制链接]
一个学渣 发表于 2024-4-23 09:28
本帖最后由 一个学渣 于 2024-4-23 19:27 编辑


函数使用t.tips('5555')调用,我想为函数添加一个参数,让其能在调用的时候控制选择新建的tipsStyle2 ,该怎么写?求帮助




[JavaScript] 纯文本查看 复制代码
 if (!tipsDom) {
                t.initTips();
                tipsDom = parentNode.querySelector(tipsSelector);
                if (!tipsDom) {
                    debug.log('init h5player tips dom error...');
                    return false
                }
            }

            const style = tipsDom.style;
            tipsDom.innerText = str;

            for (var i = 0; i < 3; i++) {
                if (this.on_off[i]) clearTimeout(this.on_off[i]);
            }

            function showTips () {
                style.display = 'block';
                t.on_off[0] = setTimeout(function () {
                    style.opacity = 1;
                }, 50);
                t.on_off[1] = setTimeout(function () {
                    // 隐藏提示框和还原样式
                    style.opacity = 0;
                    style.display = 'none';
                    if (backupStyle && backupStyle !== 'style-backup:none') {
                        parentNode.setAttribute('style', backupStyle);
                    }
                }, 2000);
            }

            if (style.display === 'block') {
                style.display = 'none';
                clearTimeout(this.on_off[3]);
                t.on_off[2] = setTimeout(function () {
                    showTips();
                }, 100);
            } else {
                showTips();
            }
        },
        /* 设置提示DOM的样式 */
        initTips: function () {
            const t = h5Player;
            const parentNode = t.getTipsContainer();
            if (parentNode.querySelector('.' + t.tipsClassName)) return

            // top: 50%;
            // left: 50%;
            // transform: translate(-50%,-50%);
            //通知提示背景透明度
            //margin-left: 20px;离左边一段距离 margin-top right右侧对齐
            const tipsStyle = `
        position: absolute;
        z-index: 999999;
        font-size: ${t.fontSize || 16}px;
        padding: 5px 10px;
        margin-right: 120px;
        background: rgba(0,0,0,0.7);
        color:white;
        top: 0;
        right: 0;
        transition: all 500ms ease;
        opacity: 0;
        border-bottom-right-radius: 5px;
        display: none;
        -webkit-font-smoothing: subpixel-antialiased;
        font-family: 'microsoft yahei', Verdana, Geneva, sans-serif;
        -webkit-user-select: none;
      `;
            
   [color=#c678dd]const[/color] [color=#d19a66]tipsStyle2[/color] [color=#56b6c2]=[/color] [color=#98c379]`[/color]
[color=#98c379]        position: absolute;[/color]
[color=#98c379]        z-index: 999999;[/color]
[color=#98c379]        font-size: [/color][color=#be5046]${[/color]t[color=#98c379].[/color][color=#e06c75]fontSize[/color][color=#98c379] [/color][color=#56b6c2]||[/color][color=#98c379] [/color][color=#d19a66]16[/color][color=#be5046]}[/color][color=#98c379]px;[/color]
[color=#98c379]        padding: 5px 10px;[/color]
[color=#98c379]        margin-right: 120px;[/color]
[color=#98c379]        background: rgba(0,0,0,0.7);[/color]
[color=#98c379]        color:white;[/color]
[color=#98c379]        top: 0;[/color]
[color=#98c379]        right: 0;[/color]
[color=#98c379]        transition: all 500ms ease;[/color]
[color=#98c379]        opacity: 0;[/color]
[color=#98c379]        border-bottom-right-radius: 5px;[/color]
[color=#98c379]        display: none;[/color]
[color=#98c379]        -webkit-font-smoothing: subpixel-antialiased;[/color]
[color=#98c379]        font-family: 'microsoft yahei', Verdana, Geneva, sans-serif;[/color]
[color=#98c379]        -webkit-user-select: none;[/color]
[color=#98c379]      `[/color];

const tips = document.createElement('div');
            tips.setAttribute('style', tipsStyle);
            tips.setAttribute('class', t.tipsClassName);
            parentNode.appendChild(tips);
        },
        on_off: new Array(3),
        rotate: 0,
        fps: 30,

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

axius 发表于 2024-4-23 10:38
t.initTips(type = 1);
// 以下函数中判断, style1为默认的样式, 当type不为1时,为style2样式
let tipsStyle = type === 1 ? style1 : style2
 楼主| 一个学渣 发表于 2024-4-23 12:37
axius 发表于 2024-4-23 10:38
t.initTips(type = 1);
// 以下函数中判断, style1为默认的样式, 当type不为1时,为style2样式
let tipsSt ...

只加一句不够吧?提示type未定义

  initTips: function () {
            const t = h5Player;
            const parentNode = t.getTipsContainer();
            if (parentNode.querySelector('.' + t.tipsClassName)) return
let tipsStyle0 = type === 1 ? tipsStyle : tipsStyle2(这里提示type未定义)
      
            const tipsStyle = `
        position: absolute;
        z-index: 999999;
        font-size: ${t.fontSize || 16}px;
        padding: 5px 10px;
        margin-right: 120px;
        background: rgba(0,0,0,0.7);
      
      `;

const tipsStyle2 = `
        position: absolute;
        z-index: 999999;
        font-size: ${t.fontSize || 16}px;
        padding: 5px 10px;
        margin-right: 120px;
        background: rgba(0,0,0,0.7);
      
      `;
            const tips = document.createElement('div');
            tips.setAttribute('style', tipsStyle);
            tips.setAttribute('class', t.tipsClassName);
            parentNode.appendChild(tips);
        },
        on_off: new Array(3),
        rotate: 0,
        fps: 30,
axius 发表于 2024-4-23 15:28
一个学渣 发表于 2024-4-23 12:37
只加一句不够吧?提示type未定义

  initTips: function () {

initTips: function (type=1) {}  //函数初始化的时候,设置参数
//调用函数的时候,  如果type为2 就 initTips(2); 如果type为1 可以不传
 楼主| 一个学渣 发表于 2024-4-23 19:20
axius 发表于 2024-4-23 15:28
initTips: function (type=1) {}  //函数初始化的时候,设置参数
//调用函数的时候,  如果type为2 就 ini ...

不知道为什么,可能函数找的不对吧,加上了就失效
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止回复与主题无关非技术内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-5-10 00:34

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表