
Security News
npm Adopts OIDC for Trusted Publishing in CI/CD Workflows
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
floating-button-plugin
Advanced tools
一个简单易用的浮动按钮插件,支持拖拽、自定义样式、位置记忆等功能。
npm install floating-button-plugin
import FloatingButton from 'floating-button-plugin';
const button = new FloatingButton({
text: '联系我们',
link: 'https://example.com'
});
const button = new FloatingButton({
text: '联系我们',
link: 'https://example.com',
position: 'bottom|right', // 支持 'top|left', 'right|center' 等灵活组合
offset: 20,
visible: true,
debug: false,
icon: {
type: 'url', // 'url' | 'base64' | 'fontawesome'
value: 'https://example.com/icon.png',
width: '20px',
height: '20px'
},
style: {
backgroundColor: '#42b983',
color: '#ffffff',
fontSize: '14px',
padding: '12px 24px',
borderRadius: '4px',
boxShadow: '0 2px 12px rgba(0,0,0,0.1)'
}
});
支持的位置组合:
top|left
: 左上角top|center
: 顶部中间top|right
: 右上角center|left
: 左侧中间center|center
: 正中心center|right
: 右侧中间bottom|left
: 左下角bottom|center
: 底部中间bottom|right
: 右下角const button = new FloatingButton({
text: '联系我们',
link: 'https://example.com',
position: 'center|right', // 右侧中间
offset: 20 // 距离边缘的偏移量
});
支持三种类型的图标:
const button = new FloatingButton({
text: '联系我们',
icon: {
type: 'url',
value: 'https://example.com/icon.png',
width: '20px', // 可选
height: '20px' // 可选
}
});
const button = new FloatingButton({
text: '联系我们',
icon: {
type: 'base64',
value: 'iVBORw0KGgoAAAANSUhEUgAA...', // Base64 图片编码
width: '20px',
height: '20px'
}
});
const button = new FloatingButton({
text: '联系我们',
icon: {
type: 'fontawesome',
value: 'fas fa-phone', // Font Awesome 类名
width: '16px' // 控制图标大小
}
});
Font Awesome 说明:
- 使用
fontawesome
类型时,插件会自动从 CDN 加载 Font Awesome 6.0.0- 无需手动安装或引入 Font Awesome 包
- 支持所有免费版图标,包括 Solid (
fas
)、Regular (far
) 和 Brands (fab
)- 图标名称可以在 Font Awesome 官网 查找
- 示例:
- 实心电话图标:
fas fa-phone
- 空心信封图标:
far fa-envelope
- GitHub 图标:
fab fa-github
// 显示按钮
button.show();
// 隐藏按钮
button.hide();
// 切换显示状态
button.setVisible(true | false);
// 销毁按钮
button.destroy();
开启调试模式可以在控制台查看按钮的操作日志:
const button = new FloatingButton({
text: '联系我们',
link: 'https://example.com',
debug: true // 开启调试模式
});
export default {
beforeDestroy() { // Vue 2.x
this.$refs.floatingBtn?.destroy();
},
beforeUnmount() { // Vue 3.x
this.$refs.floatingBtn?.destroy();
}
}
<template>
<div>
<!-- 其他内容 -->
<floating-button
text="联系我们"
link="https://example.com"
position="bottom|right"
:offset="20"
:visible="true"
:debug="false"
:icon="{
type: 'fontawesome',
value: 'fas fa-phone',
width: '16px'
}"
:style="{
backgroundColor: '#42b983',
color: '#ffffff',
fontSize: '14px',
padding: '12px 24px',
borderRadius: '4px',
boxShadow: '0 2px 12px rgba(0,0,0,0.1)'
}"
/>
</div>
</template>
<script>
import { FloatingButton } from 'floating-button-plugin';
export default {
components: {
FloatingButton
}
}
</script>
import { createApp } from 'vue'
import FloatingButton from 'floating-button-plugin'
const app = createApp(App)
// 方式一:注册为全局组件,之后可以在任意组件中直接使用 <floating-button> 标签
app.component('floating-button', FloatingButton)
// 方式二:作为插件使用,自动完成全局注册
app.use(FloatingButton)
app.mount('#app')
使用全局注册后,可以在任意组件中直接使用,无需再次导入:
<template>
<div>
<!-- 任意组件中都可以直接使用 floating-button -->
<floating-button
text="联系我们"
link="https://example.com"
/>
</div>
</template>
<script>
export default {
// 不需要再次 import 和注册组件
// 已经全局可用
}
</script>
<template>
<div>
<floating-button
ref="floatingBtn"
text="联系我们"
link="https://example.com"
/>
<button @click="toggleButton">切换显示</button>
</div>
</template>
<script>
export default {
methods: {
toggleButton() {
// 通过 ref 访问按钮实例方法
const btn = this.$refs.floatingBtn;
btn.setVisible(!btn.visible);
}
}
}
</script>
MIT
FAQs
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
Research
/Security News
A RubyGems malware campaign used 60 malicious packages posing as automation tools to steal credentials from social media and marketing tool users.
Security News
The CNA Scorecard ranks CVE issuers by data completeness, revealing major gaps in patch info and software identifiers across thousands of vulnerabilities.