1.0.11 • Published 2 years ago
js-component-enhance v1.0.11
JS-组件
作者:likecodeBoy(田浩云)
安装
npm i js-component-enhance
vue
// main.js中
import 'js-component-enhance/enhance-ui.min.css'
// 在其vue文件中
<template>
<div>
<div class="page-title"></div>
</div>
</template>
import {Aside} from 'js-component-enhance/index.js'
export default{
data(){
return {}
}
mounted(){
new Aside({
element: document.querySelector('.page-title'),
color: 'gray',
position: 'right',
model:'circle',
callback: () => {
console.log('这是回到顶部的回调');
}
})
}
}
HTML
<div class="top-banner"> </div>
<link rel="stylesheet" href="./node_modules/js-component-enhance/enhance-ui.min.css">
<script src="./node_modules/js-component-enhance/index.js"></script>
<script>
new EnhanceUi.Swiper(){
element:document.querySelector('.swiper')
mode:'dark',
type:'comment'
data:[
{
'img':'....',
'text':'....',
'url':'....'
}
]
callback:(index)=>{
console.log('swiper 的回调'+index)
}
});
</script>
JS CSS
// xx.css
@import 'node_modules/js-component-enhance/enhance-ui.min.css'
//xxx.js
import './node_modules/js-component-enhance/index.js'
new EnhanceUi.Aside({
element: document.querySelector('.back-top'),
color: 'gray',
position: 'right',
model:'circle',
callback: () => {
console.log('这是回到顶部的回调');
}
})
new EnhanceUi.Topbanner({
element: document.querySelector('.top-banner'),
mode: 'dark',
location: 'top',
isFixed: true,
callback: () => {
console.log('这是顶部导航回调');
}
})
<script scr =".../xx.js" type="module">
API
(1)Aside
返回至顶部 + 返回至主页
属性 | 说明 | 类型 | 默认值 | 是否必传 |
---|---|---|---|---|
src | 调转到某个地址 | string | https://3g.163.com/touch/news/ | 否 |
element | 组件标签容器 | 单个dom元素 | null | 是 |
color | 背景颜色 | string | gray | 否 |
position | 仅靠左边或者右边 | string | right | 否 |
callback | 组件点击事件的回调函数 | function | 无 | 否 |
backtop | 是否生成返回顶部的元素 | 布尔值 | true | 否 |
backhome | 是否生成跳转主页的元素 | 布尔值 | true | 否 |
model | 组件的形状 | string | circle | 否 |
代码示例:
//html
<div class = "page-title"> </div>
// 为了实现淡入淡出效果,您可以在内容填充一部分的时候,再添加此组件,划到底部的时候会显示!
//js
new EnhanceUi.Aside({
element: document.querySelector('.page-title'),
color: 'gray',
position: 'right',
model:'circle',
callback: () => {
console.log('这是回到顶部的回调');
}
})
(2)EhanceButton
打开App的按钮
属性 | 说明 | 类型 | 默认值 | 是否必传 |
---|---|---|---|---|
element | 组件标签容器 | 单个dom元素 | null | 是 |
text | 展示内容 | string | 网易新闻 | 否 |
type | 类型 article comment 评论类型之后会有箭头 | string | article | 否 |
color | 字体颜色 red blue | string | red | 否 |
callback | 组件点击事件的回调函数 | function | 无 | 否 |
src | 跳转的地址 | string | https://3g.163.com/touch/news/ | 否 |
代码示例:
//html
<span class="enhance-button"></span>
//js
new EnhanceUi.EnhanceButton({
element:document.querySelector('.enhance-button'),
text: '网易新闻',
src:'https://www.baidu.com/s?ie=UTF-8&wd=npm',
callback:()=>{
console.log('EnhanceButton的回调');
}
})
(3)Swiper
轮播图
属性 | 说明 | 类型 | 默认值 | 是否必传 |
---|---|---|---|---|
duration | 间隔时间 | number | 500 | 否 |
threshold | 移动界限 | number | 50 | 否 |
interval | 自动播放的时间间隔 | number | 5000 | 否 |
direction | 方法 horizontal (水平) vertical(垂直) | string | horizontal | 否 |
container | 组件标签容器 | 单个dom元素 | null | 是 |
text | 展示内容 | string | 详情 | 否 |
type | 类型 article comment | string | article | 否 |
callback | 组件点击事件的回调函数 | function | 无 | 否 |
url | 跳转的地址 | string | https://3g.163.com/touch/news/ | 否 |
data | 轮播的数据信息 | Array | null | 是 |
mode | 背景颜色 light dart | string | light | 否 |
position | 位置 置顶top 置底 bottom | string | bottom | 否 |
代码示例:
//html
<div class= "swiper"></div>
//js
new EnhanceUi.Swiper({
container:document.querySelector('.swiper'),
mode: 'dark',
type: 'comment',
position:'bottom',
data: [{
'img': 'https://img.36krcdn.com/20200828/v2_09cbece3aa684ad2a4f3a58daa4f6f10_img_000',
'text': '111热门文章:父母最大的悲哀是年老后在子女面前变得小心翼翼',
'url': 'www.baidu.com'
}],
callback: (index) => {
console.log('这是swiper回调,index为'+index);
}
})
(4)TextMoreButton
查看更多文章、更多评论的按钮
属性 | 说明 | 类型 | 默认值 | 是否必传 |
---|---|---|---|---|
element | 组件标签容器 | 单个dom元素 | null | 是 |
text | 按钮内容 | string | 点击查看更多 | 否 |
type | 类型 article comment | string | article | 是 |
color | 字体颜色 red blue | string | blue | 否 |
callback | 组件点击事件的回调函数 | function | 无 | 否 |
default | 展开内容之前按钮所展示的内容 | string | 查看更多 | 否 |
url | 跳转的地址 | string | https://3g.163.com/touch/news/ | 否 |
代码示例:
// html
<div class = "comment-button"></div>
// js
new EnhanceUi.TextMoreButton({
element: document.querySelector('.comment-button'),
text: '打开"App",查看更多评论',
type: 'comment',
color: 'red',
callback: () => {
console.log('这是TextMoreButton回调');
}
})
(5)TopBanner
吸顶吸底的logo banner
属性 | 说明 | 类型 | 默认值 | 是否必传 |
---|---|---|---|---|
element | 组件标签容器 | 单个dom元素 | null | 是 |
mode | 主题 ligth dark | stromg | light | 否 |
title | 展示内容 | string | 网易新闻 | 否 |
desc | 描述 | string | 看遍天下事 | 否 |
location | 类型 bottom top | string | top | 否 |
callback | 组件点击事件的回调函数 | function | 无 | 否 |
url | 跳转的地址 | string | https://3g.163.com/touch/news/ | 否 |
代码示例:
//html
<div class="top-banner"></div>
//js
new EnhanceUi.Topbanner({
element: document.querySelector('.top-banner'),
mode: 'dark',
location: 'top',
isFixed: true,
callback: () => {
console.log('这是顶部导航回调');
}
})
(6)VideoButton
查看更多视频按钮
属性 | 说明 | 类型 | 默认值 | 是否必传 |
---|---|---|---|---|
element | 组件标签容器 | 单个dom元素 | null | 是 |
text | 按钮内容 | string | 打开"App",查看更多精彩视频 | 否 |
color | 背景颜色 red pink | string | red | 否 |
callback | 组件点击事件的回调函数 | function | 无 | 否 |
url | 跳转的地址 | string | https://3g.163.com/touch/news/ | 否 |
src | 显示的图片 | string | null | 否 |
代码示例:
// html;
<div class="video-button"></div>
//js
new EnhanceUi.VideoButton({
element: document.querySelector('.video-button'),
mode: 'light',
color: 'red',
src: 'https://cms-bucket.ws.126.net/2021/0525/3012c74fp00qtniu0008tc000go006yc.png',
callback: () => {
console.log('这是videoButton回调');
}
})