本帖最后由 一个学渣 于 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, |