js css 鼠标移入某个区域滑出一个框的效果怎么做?

JavaScript08

js css 鼠标移入某个区域滑出一个框的效果怎么做?,第1张

1、输入代码,其中button是鼠标要滑动的地方,滑过button时,class为content的内容就要显示出来,鼠标滑出去的时候,这块内容就需要重新隐藏起来。

2、把黑色内容的部分初始状态写成隐藏。只需要在class为content里写上display:none,即可。

3、来看下代码和浏览器中的效果。可以看到黑色内容部分已经不见了。

4、把onmouseover和onmouseout两个事件作用在button上面,再写overShow()和overHide()两个 函数。可以看到在函数中通过改content的display属性来实现显示隐藏的效果。

5、在浏览器中就可以看到效果了。

(function($) {

$.fn.huadong = function( obj, obja, time ) {

this.height($(window).height()).css({'position':'absolute', 'top':'0px', 'left' : '0px'})//首先把最外层的标签对象设置为浮动, 上边为0, 左边也为0

var left = $(obj).width()//取得左边栏的宽度

$(obj).height($(window).height()).width(0).hide()//将左边栏的高度设置为浏览器的高度, 宽度为0, 并隐藏掉!这样是为了页面载入的时候初始化

$(obja).click(function(){ //给触发按钮绑定点击事件,也就是鼠标点击触发按钮后执行的动作

$(obj).show().animate({'width':left + 'px'}, time)//把左边栏的宽度设置为原来的宽度并显示出来, 根据设定的时间慢慢展现

})

$(obj).mouseout(function(){ //绑定左边栏鼠标移开事件

$(this).animate({'width':'0px'}, time, function(){ $(this).hide()})//又把左边栏的宽度设置为0, 并且隐藏

})

}

})(jQuery)

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

}