js 定位DIV

JavaScript014

js 定位DIV,第1张

Div绝对定位js代码

function showDiv(name)

{

var cf=document.getElementById("DivID")

var oImg=document.getElementById(name)

var eT=0,eL=0,p=oImg

var sT=document.body.scrollTop,sL=document.body.scrollLeft

var eH=oImg.height+25,eW=oImg.width

while(p&&p.tagName!="BODY"){eT+=p.offsetTopeL+=p.offsetLeftp=p.offsetParent}

cf.style.top=((document.body.clientHeight-(eT-sT)-eH>=cf.style.posHeight)?eT+eH:eT-cf.style.posHeight)-4

cf.style.left=((document.body.clientWidth-(eL-sL)>=cf.style.posWidth)?eL:eL+eW-cf.style.posWidth)

}

他们是一个东西,没什么区别。js组件就是把一系列的功能封装起来,包装成一个对象。比如一个表格组件,一个表单组件等等。一个组件必然包含了某种特定的职能,目的在于可以复用。比方说,你的网站需要展示一个万年历,那么最基本的方法,就是自己画table,自己写逻辑,麻烦得一笔。假如我有100个页面,那么是不是说我要把这些代码复制100遍??所以,为了避免这种麻烦,就可以把万年历封装成一个组件,然后做成一个js文件发布,别人下载就行了。

如果是在父附件中,可以通过ref

<component1 ref="ref1"></component>

在父组件中 this.$refs.ref1

在子组件中通过 this.$parent获取父组件