jQuery实现鼠标拖动改变Div高度
最近项目中需要在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高度的更多相关文章
- 鼠标拖动改变DIV等网页元素的大小的最佳实践
1.初次实现 1.1 html代码 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" la ...
- jquery 拖动改变div大小
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- 调用jquery的resize方法改变div的宽度和高度在IE中不变,在谷歌中可以正常显示
1.jquery代码: 1.1问题的版本: $(function() { haituheight(); $(window).resize(function(){ haituheight(); }); ...
- jQuery鼠标拖曳改变div大小(模拟textarea右下角拖曳)
jQuery.fn.extend({ drag: function() { $(document).off("mouseup.drag").on("mouseup.dra ...
- js改变div高度
用bootsrap响应式布局的时候,遇到个很恶心的问题:左边栏很短很难看!! 于是,想用js来自动改变左边的高度,没成功!!原来是设置的时候,没加单位,坑爹了. 参考:http://blog.sina ...
- [置顶] 原创鼠标拖动实现DIV排序
先上效果图: 对比传统的排序,这是一个很不错的尝试,希望对大家有启发. 大家可以参考我的上一篇博文:http://blog.csdn.net/littlebo01/article/details/12 ...
- jquery实现鼠标拖动
<html> <head> <script type='text/javascript' src='js/jquery-1.5.1.js'></scr ...
- C# 运行时通过鼠标拖动改变控件的大小
来源:http://blog.csdn.net/yanleigis/article/details/1819447 using System; using System.Collections.Gen ...
- jquery动态改变div宽度和高度
效果体验:http://keleyi.com/keleyi/phtml/jquery/23.htm 完整代码: <!DOCTYPE html PUBLIC "-//W3C//DTD X ...
随机推荐
- WindowsForm--Bubble User Control
创建一个自定义用户控件,拖入一个label:lblWords,和一个richTextBox:txtWords 代码: using System; using System.Collections.Ge ...
- UIButton的titleLabe setAttributeSting 首次不起作用
环境xcode7.3 ios9.3 真机模拟器均出现 UIButton的titleLabe setAttributeSting 首次不起作用,之后每一次 都正常,百思不得解,无奈之下改变策略,讲but ...
- delphi 一个线程和主界面的交互的演示代码
求一个线程和主界面的交互的演示代码求一个线程和主界面的交互的演示代码.线程和主界面处于两个Unit.线程中的user中不能引用主窗口.我只是想学习一下,线程和主界面交互的方法.去网上查了好几天资料,能 ...
- Emergency(山东省第一届ACM省赛)
Emergency Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 Kudo’s real name is not Kudo. H ...
- StackPanel在增加控件的问题
今天遇到这样一个问题,就是我做了一个自定义控件.然后加到StackPanel中, <StackPanel Height="676" HorizontalAlignment=& ...
- 一段比较有意思的代码——介绍system verilog中的新增幅值语句
system verilog中新加了很多幅值语句,虽然都只适用于阻塞幅值,但是在某些场合中非常实用. 下面是一段有意思的代码,覆盖了一些用法. package definitions; typedef ...
- 外壳exe通过反射调用dll时
外壳exe通过反射调用dll时,dll是 4.0的框架,外壳exe也需要编译成4.0的框架,如果dll本身有调用32位的dll,那么外壳exe也需要编译成32位. 调试时报的那个错,直接继续运行,不影 ...
- 【小错误】ORA-00265: instance recovery required, cannot set ARCHIVELOG mode
1.错误描述:今天在起归档的时候报一下错误: SQL> alter database archivelog; alter database archivelog * ERROR at line ...
- session 丢失和解决方案
在ASP.NET的开发中,总遇到Session丢失.最常见的情况是当用户登录后将用户信息保存在Session中例如Session["user"]=user;在其后的页面中检查Ses ...
- bash profile .bashrc
/etc/profile:此文件为系统的每个用户设置环境信息,当用户第一次登录时,该文件被执行. 并从/etc/profile.d目录的配置文件中搜集shell的设置. /etc/bashrc:为每一 ...