js特效-下拉菜单
来源:互联网 发布:mac打印色彩调整图案 编辑:程序博客网 时间:2024/04/30 01:28
js源码slide.js:
// JavaScript Document
/**
* @function slide向一边显示块
* @direction objId显示块的id,direction方向,speed速度
*/
function slide(objId, direction, speed, destorySign){
var effect = this;
var obj = null;
var top = 0;
var bottom = 0;
var left = 0;
var right = 0;
var container = null;
var direction = direction;
var speed = speed ? speed : 20;
var timer = null;
var destorySign = destorySign ? destorySign : false;
var init = function(){
obj = document.getElementById(objId);
obj.style.position= "absolute";
obj.style.display = "block";
top = obj.offsetTop;
left = obj.offsetLeft;
var parent = obj.parentNode;
container = document.createElement("div");
container.style.overflow = "hidden";
container.style.position = "absolute";
container.style.zIndex = 1000;
container.appendChild(obj);
parent.appendChild(container);
if(parent.tagName != "BODY"){
container.style.width = obj.offsetWidth + "px";
container.style.height = obj.offsetHeight + "px";
container.style.top = top+"px";
container.style.left = left+"px";
top = 0;
left = 0;
}
else{
container.style.width = "100%";
container.style.height = "100%";
container.style.top = "0px";
container.style.left = "0px";
}
if(direction == "up"){
obj.style.top = 0-obj.offsetHeight+"px";
obj.style.left = left+"px";
}
else if(direction == "down"){
obj.style.top = container.offsetHeight+"px";
obj.style.left = left+"px";
}
else if(direction == "left"){
obj.style.left = 0-obj.offsetWidth+"px";
obj.style.top = top+"px";
}
else{
obj.style.left = container.offsetWidth+"px";
obj.style.top = top+"px";
}
obj.style.margin = "0px";
container.style.display = "none";
};
this.show = function(func){
clearInterval(timer);
timer = setInterval(function(){effect.animateShow(func);}, 50);
};
this.hide = function(func){
clearInterval(timer);
timer = setInterval(function(){effect.animateHide(func);}, 50);
};
this.animateShow = function(func){
container.style.display = "block";
obj.style.display = "block";
if(direction == "up"){
if(obj.offsetTop + speed <= top)
obj.style.top = obj.offsetTop + speed + "px";
else{
obj.style.top = top+"px";
clearInterval(timer);
if(func)
func();
}
}
else if(direction == "down"){
if(obj.offsetTop - speed >= top)
obj.style.top = obj.offsetTop - speed +"px";
else{
obj.style.top = top+"px";
clearInterval(timer);
if(func)
func();
}
}
else if(direction == "left"){
if(obj.offsetLeft + speed <= left)
obj.style.left = obj.offsetLeft + speed + "px";
else{
obj.style.left = left+"px";
clearInterval(timer);
if(func)
func();
}
}
else{
if(obj.offsetLeft - speed >= left)
obj.style.left = obj.offsetLeft - speed + "px";
else{
obj.style.left = left+"px";
clearInterval(timer);
if(func)
func();
}
}
};
this.animateHide = function(func){
container.style.display = "block";
if(direction == "up"){
if(obj.offsetTop - speed >= 0-obj.offsetHeight){
obj.style.top = obj.offsetTop - speed + "px";
}
else{
obj.style.top = 0-obj.offsetHeight + "px";
container.style.display = "none";
clearInterval(timer);
this.destory();
if(func)
func();
}
}
else if(direction == "down"){
if(obj.offsetTop + speed <= container.offsetHeight)
obj.style.top = obj.offsetTop + speed +"px";
else{
obj.style.top = container.offsetHeight+"px";
container.style.display = "none";
clearInterval(timer);
this.destory();
if(func)
func();
}
}
else if(direction == "left"){
if(obj.offsetLeft - speed >= 0-obj.offsetWidth)
obj.style.left = obj.offsetLeft - speed + "px";
else{
obj.style.left = 0 - right + "px";
container.style.display = "none";
clearInterval(timer);
this.destory();
if(func)
func();
}
}
else{
if(obj.offsetLeft + speed <= container.offsetWidth)
obj.style.left = obj.offsetLeft + speed + "px";
else{
obj.style.left = container.offsetWidth+"px";
container.style.display = "none";
clearInterval(timer);
this.destory();
if(func)
func();
}
}
};
this.destory = function(){
if(destorySign){
var parent = container.parentNode;
parent.removeChild(container);
container.childNodes[0].removeAttribute("style");
parent.appendChild(container.childNodes[0]);
}
};
init();
return this;
};
测试源码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>slide</title>
<style>
*{
padding:0px;
margin:auto;
}
#menu{
width:100px;
}
#menu_titile{
border:1px #000000 solid;
width:100px;
}
#menu_list{
border:1px #CCCCCC solid;
width:100px;
background:#FFF;
}
li{
list-style-type:none;
}
</style>
</head>
<body>
<div id="menu">
<div id="menu_title">menu</div>
<div id="menu_list">
<ul>
<li>menu1</li>
<li>menu2</li>
<li>menu3</li>
<li>menu4</li>
<li>menu5</li>
</ul>
</div>
</div>
<div>
</div>
</body>
<script language="javascript" src="slide.js"></script>
<script language="javascript">
var m = new menu("menu_title", "menu_list", "blind", "up");
function menu(menuId, menuListId, effect, direction){
var effectObj = null;
var menu = null;
var init = function(){
menu = document.getElementById(menuId);
effectObj = slide(menuListId, direction, 30);
menu.parentNode.onmouseover = effectObj.show;
menu.parentNode.onmouseout = effectObj.hide;
};
init();
return this;
};
</script>
</html>
- js特效-下拉菜单
- js特效-震动下拉菜单、抖动窗口
- js 简单的类下拉菜单特效
- JS特效之多层下拉菜单
- 城市地区级联二级下拉选择菜单js特效
- 导航栏二级下拉菜单的js特效
- js实现小特效 下拉菜单的折叠
- jquery特效 简易下拉菜单
- 导航下拉二级菜单特效
- js特效-渐现菜单
- JS制作下拉菜单
- js实现下拉菜单
- js select 下拉菜单
- js 菜单下拉跳转
- js搜索下拉菜单
- js简单下拉菜单
- 三级下拉菜单 js
- js二级下拉菜单
- 嘿嘿。
- 如何快速获得积分啊
- 将命令的返回值赋给变量
- 多学一些还是有用的
- 第一篇博文
- js特效-下拉菜单
- 关于Server.MapPath怎样取绝对路径的问题
- 你的代码真的很健壮吗
- flex之数据绑定
- Ibatis返回结果集
- 脚本加入crontab的几种方法
- psftp的用法(超级详细)
- 什么是反向代理?
- 题外话——第九届学生团体活动月开幕式感触