js实现鼠标滑入滑出效果,怎么做?不用id

JavaScript09

js实现鼠标滑入滑出效果,怎么做?不用id,第1张

clientHeight

然后递归,直到这个高度为0,或者直到这个高度为一个指定的高度

function showBox()

{

if (sb != null){

clearTimeout(sb)

}

if (cb != null) {

clearTimeout(cb)

}

var o = $('rbbox')

o.style.display = 'block'

var H = parseInt(o.style.height)

o.style.height = (o.clientHeight + Math.ceil((55 - o.clientHeight) * 0.035)) + "px"

if (o.clientHeight <55) {

sb = setTimeout(function(){showBox()}, 2)

}

else {

cb = setTimeout(function(){closeBox()}, 3800)

return

}

}

function closeBox(msg)

{

if (cb != null) {

clearTimeout(cb)

}

var o = $('rbbox')

var dy = Math.ceil((parseInt(o.style.height) - 4) * 0.875).toString()

o.style.height = dy + "px"

if(o.clientHeight <= 5){

document.getElementById("rbbox").style.display = 'none'

return

}

cb = setTimeout(function(){closeBox()}, 3)

}

div#rbbox {

position: fixed

right: 2px

bottom: 2px

height: 0px

width: auto

overflow: hidden

border:1px #ff0000 solid

background-color: #FFCC00

text-align:justify

}

1:使用js的插件 目前主流的js库 比如jq 也有手势的插件,

2:还有移动端的zepto库 也有手势插件,

3:另外还有个叫QuoJS的手势插件 这个插件不依赖任何的库,

4:早期的应该是用wml语言支持的WMLScript实现。

5:举例:使用iscroll.js实现

1)下载iScroll.js,百度搜索iScroll.js下载即可

2)引入iScroll.js,在要使用滑动效果的地方,引入iScroll.js文件

3)编写规范的html格式

只有如下格式才能实现滑动效果

<div id="wrapper">

<div class="scroll">

这个区域可以滑动

</div>

</div>

如下格式不能滑动

<div id="wrapper">

<div class="other">这个区域可以滑动</div>

<div class="scroll">

这个区域不可以滑动了

</div>

</div>

只有wrapper的第一个子元素才能实现滑动效果。

4)编写js调用代码

var Scroll = new iScroll('wrapper',{hScrollbar:false, vScrollbar:false})

第一参数必需是滑动元素的父元素的id。

主要参数一览:

hScroll: true, 左右滑动,默认为true

vScroll: true,上下滑动

hScrollbar: true, 是否显示y轴滚动条,默认为显示

vScrollbar: true,是否显示X轴滚动条,默认为显示