最近项目中需要在DashBoard页面做一个事件通知栏,该通知栏固定位于页面底部,鼠标拖动该DIV实现自动改变高度扩展内容显示区域。

以下是一个设计原型,基于jQuery实现,只实现了拖动效果,没有做页面美化,可以根据需求做相应修改。

直接上代码

 <!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<title>Div随鼠标拖动改变高度</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script src="jquery-1.8.3.min.js"></script>
<style type="text/css">
html, body{ height: 100%; margin: 0; padding: 0; }
#footer { position:fixed; bottom:0; left:0; width:100%; height:30px; background-color:#B8D0FA;}
#expander{ width:100%; height:6px; background-color:#999;}
#expander:hover{ cursor:n-resize;}
</style>
<script>
$(function(){
var src_posi_Y = 0, dest_posi_Y = 0, move_Y = 0, is_mouse_down = false, destHeight = 30;
$("#expander")
.mousedown(function(e){
src_posi_Y = e.pageY;
is_mouse_down = true;
});
$(document).bind("click mouseup",function(e){
if(is_mouse_down){
is_mouse_down = false;
}
})
.mousemove(function(e){
dest_posi_Y = e.pageY;
move_Y = src_posi_Y - dest_posi_Y;
src_posi_Y = dest_posi_Y;
destHeight = $("#footer").height() + move_Y;
if(is_mouse_down){
$("#footer").css("height", destHeight > 30 ? destHeight : 30);
}
});
});
</script>
</head>
<body>
<div style="width:100%; height:1000px; background-color:#F2F2F2;"></div>
<div id="footer"><div id="expander"></div><span id="info">It's Your Contents !</span></div>
</body>
</html>

jQuery实现鼠标拖动改变Div高度的更多相关文章

  1. 鼠标拖动改变DIV等网页元素的大小的最佳实践

    1.初次实现 1.1 html代码 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" la ...

  2. jquery 拖动改变div大小

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  3. 调用jquery的resize方法改变div的宽度和高度在IE中不变,在谷歌中可以正常显示

    1.jquery代码: 1.1问题的版本: $(function() { haituheight(); $(window).resize(function(){ haituheight(); }); ...

  4. jQuery鼠标拖曳改变div大小(模拟textarea右下角拖曳)

    jQuery.fn.extend({ drag: function() { $(document).off("mouseup.drag").on("mouseup.dra ...

  5. js改变div高度

    用bootsrap响应式布局的时候,遇到个很恶心的问题:左边栏很短很难看!! 于是,想用js来自动改变左边的高度,没成功!!原来是设置的时候,没加单位,坑爹了. 参考:http://blog.sina ...

  6. [置顶] 原创鼠标拖动实现DIV排序

    先上效果图: 对比传统的排序,这是一个很不错的尝试,希望对大家有启发. 大家可以参考我的上一篇博文:http://blog.csdn.net/littlebo01/article/details/12 ...

  7. jquery实现鼠标拖动

    <html>   <head>   <script type='text/javascript' src='js/jquery-1.5.1.js'></scr ...

  8. C# 运行时通过鼠标拖动改变控件的大小

    来源:http://blog.csdn.net/yanleigis/article/details/1819447 using System; using System.Collections.Gen ...

  9. jquery动态改变div宽度和高度

    效果体验:http://keleyi.com/keleyi/phtml/jquery/23.htm 完整代码: <!DOCTYPE html PUBLIC "-//W3C//DTD X ...

随机推荐

  1. System.Data.OleDb.OleDbException: 未指定的错误的解决方法

    异常详细信息: System.Data.OleDb.OleDbException: 未指定的错误 这个错误是access数据库特有的错误,当access频繁读取或操作过多的时候就会发生这个错误,微软官 ...

  2. Jenkins若干小问题

    1. Jenkins上不能直接在shell中调用scp命令来执行上传下载操作,核心问题是scp需要输入密码. 为了可以直接将密码传递过去.我们安装  sshpass 来透传密码 a. 安装sshpas ...

  3. Disconf

    通常我们会做如下配置:(disconf 2.6.21) <!-- 一次扫描 --> <bean id="disconfMgrBean" class="c ...

  4. 判断一个数num是否是2的幂(乐视题)

    思路“num &(num-1)==0 返回true,否者返回false.代码如下: boolean isPower(int num){ if(num<=0) return false; ...

  5. Shade Exaple1

    Shader "Custom/Diffuse Texture" { Properties { _MainTex ("Base (RGB)", 2D) = &qu ...

  6. mount什么意思

    root@Home-Cloud:/mnt# dfFilesystem           1K-blocks      Used Available Use% Mounted on/dev/root  ...

  7. Doxygen给C程序生成注释文档

    近段时间,一直在学习华为C语言编程规范(2011版),在“注释”这一章中发现了一种“Doxygen”的注释转文档工具,查看诸多相关资料,并进行编程实践,终于可以利用Doxygen给C程序生成注释文档. ...

  8. Unix 用gdb分析core dump文件

    产生core文件条件 用ulimit -c 指定core文件大小来开启core文件的生成,如:ulimit -c unlimited 用gdb分析core文件的条件 可执行程序在编译时,需加入-g参数 ...

  9. LPC2478调试___ads常见错误分析

    进行ADS外部RAM进行仿真调试过程中,出现常见错误“entry point lies  outside the image" 原因为程序空间超出范围,需要修改一个参数. 解决方法:首先在Z ...

  10. NOIP2007 矩阵取数游戏

    题目描述 帅帅经常跟同学玩一个矩阵取数游戏:对于一个给定的n*m的矩阵,矩阵中的每个元素aij均为非负整数.游戏规则如下: 1.每次取数时须从每行各取走一个元素,共n个.m次后取完矩阵所有元素: 2. ...