npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

vue-lite-popup

v1.0.2

Published

A vue component

Downloads

15

Readme

vue-lite-popup

在移动端开发时,经常会用到popupwindow这样的弹窗控件,给用户进行选项操作,android和ios中原生提供了这类控件,而在移动端前端中这类控件需要自己定义。我这里采用webpack+vue自定一个popup控件,可以在其他vue项目中直接使用。

如何使用

  1. 安装npm依赖 npm install vue-lite-popup --save
  2. 在入口处引入库
import PopupPlugin from 'vue-lite-popup';
import PopupPluginCss from 'vue-lite-popup/dist/style.css'
Vue.use(PopupPlugin);
  1. 在页面中使用
<template>
  <div class="page">
    <div v-for="(item,index) in dataList" :key="index" class="list-item">
      <div>{{index}}---</div>
      <div>{{item}}</div>
      <div style="margin-left: auto" @click="onItemClick($event,index,item)"> . . . </div>
    </div>
    <Popup ref="popupRef">
      <div class="popup-option">
        <div style="height: 50%" @click="clickAttention">关注</div>
        <div style="height: 50%" @click="clickCancelAttention">取消关注</div>
      </div>
    </Popup>
  </div>
</template>
<script>
//  import {Popup} from './../dist/index';
  export default {
    data () {
      return {
        dataList:[],
      }
    },
    mounted(){
      for(let i=0;i<20;i++){
        this.dataList.push('__'+i+'__');
      }
    },
    methods:{
      onItemClick(event,index,item){
        this.$refs.popupRef.showWithAchor(event.target,-90,10);
      },
      clickAttention(){
        console.log('关注');
        this.$refs.popupRef.close();
      },
      clickCancelAttention(){
        console.log('取消关注');
        this.$refs.popupRef.close();
      }
    },
//    components:{Popup}
  }
</script>
<style>
  @import './normalize.css';
  .page{
    width: 100%;
    height: 100%;
    overflow: auto;
  }
  .list-item{
    position: relative;
    display: flex;
    flex-flow: row nowrap;
    align-items: center;
    width: 100%;
    height: 50px;
    padding: 8px;
    margin-top: 3px;
    background: gray;
  }
  .popup-option{
    height: 60px;
    padding: 10px;
    background: #42b983;
  }
</style>

如何实现popup控件

当点击页面上任意一个dom节点时,可以通过zepto的offset()返回或设置匹配元素相对于文档的偏移。然后就可以设置popop控件的内容部分相对于文档的偏移量,通过方法控制这个popup控件展示与否,即可实现这个效果。

show(x,y){
    $(".popup-layer").children().css({left:x,top:y});
    $(".popup-layer").children().click(function (event) {
      event.stopPropagation();
    });
    this.showFlag=true;
},
showWithAchor(dom,dx,dy){
	let offsetValue=$(dom).offset();
	let left=offsetValue.left+dom.offsetWidth+dx;
	let top=offsetValue.top+dom.offsetHeight+dy;
	this.show(left,top);
}

如何在npm上发布控件

  1. 在npm上注册一个账号
  2. npm adduser
  3. npm publish

发布库的名称(package.json中的name)不能和npm上已有的重名,因此发布之前请检查

参考

  1. http://www.w3school.com.cn/jquery/css_offset.asp
  2. https://segmentfault.com/a/1190000006250554
  3. http://www.w2bc.com/Article/50764