就是一个停留在页面右侧的滑动菜单,点击可以拉出,带回调函数。宽高位置可以参数指定。插件代码如下:

(jquery的路径请自己修改)

(function($){
$.fn.sideSwitch = function(opts){ var defaults = {
contentWidth:'400px',
contentHeight:'185px',
btnWidth:'30px',
btnHeight:'80px',
initTop:'',//初始化离浏览器顶部的距离
extra:'',//因页面布局需要额外向左移动的距离
callback:''//菜单拉出后的回调函数
}
var option = $.extend(defaults,opts);
this.each(function(){//这一行的this是指$选择器选择到的对象,是一个数组
var _this = $(this);//拿到某一个div
var btndiv = _this.find('.ss_btn');
var btnTop = (parseInt(option.contentHeight)-parseInt(option.btnHeight))/2;
btndiv.css({width:option.btnWidth,height:option.btnHeight,top:btnTop,position:"absolute",cursor:"pointer"});
var contentdiv = _this.find('.ss_content');
var contentLeft = parseInt(option.btnWidth)+parseInt(btndiv.css('borderLeftWidth'))+parseInt(btndiv.css('borderRightWidth'));
contentdiv.css({width:option.contentWidth,height:option.contentHeight,position:"relative",left:contentLeft,top:"0px"}); var boxInitLeft = parseInt(document.body.clientWidth)-parseInt(option.btnWidth)-parseInt(btndiv.css('borderLeftWidth'))-parseInt(btndiv.css('borderRightWidth'))-option.extra;
var boxInitWidth = parseInt(option.btnWidth)+parseInt(btndiv.css('borderLeftWidth'))+parseInt(btndiv.css('borderRightWidth'));
_this.css({width:boxInitWidth,overflow:"hidden",position:"absolute",zIndex:999});
if(!option.initTop){option.initTop = (parseInt(document.body.clientHeight)-parseInt(_this.css('height'))-parseInt(_this.css("borderTopWidth"))-parseInt(contentdiv.css("borderTopWidth")))/2;}
_this.css({left:boxInitLeft,top:option.initTop}); var menuYloc = _this.offset().top; //当前窗口的相对偏移
$(window).scroll(function (){
var offsetTop = menuYloc + $(window).scrollTop() +"px";
_this.animate({top : offsetTop },{ duration:600 , queue:false });
}); btndiv.click(
function(){
if(parseInt(_this.css("width"))<parseInt($('.ss_content').css('width'))){
var boxNewWidth = parseInt($('.ss_content').css('width'))+parseInt($('.ss_content').css('borderLeftWidth'))+parseInt($('.ss_content').css('borderRightWidth'))+parseInt($('.ss_btn').css('width'))+parseInt($('.ss_btn').css('borderLeftWidth'))+parseInt($('.ss_btn').css('borderRightWidth')); var boxNewLeft = parseInt(document.body.clientWidth)-boxNewWidth-option.extra;
_this.animate({left:boxNewLeft+'px',width:boxNewWidth+"px"},"slow");
option.callback();
}
else{
_this.animate({left:boxInitLeft,width:"30px"},"slow");
} }
)
}); } })(jQuery)

下面再附一个使用的demo:

<!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>无标题文档</title>
<style type="text/css">
*{margin:0;padding:0;}
.div{float:left;width:30%;height:300px;border:1px solid #f00;}
</style>
<script type="text/javascript" src="../../jquery-1.8.3.min.js"></script>
<script type="text/javascript" src="jquery.sideSwitch.js"></script>
<script type="text/javascript">
$(function(){
$('#box').sideSwitch();
});
</script>
</head> <body>
<div class="div">文字文字文字</div>
<div class="div">文字文字文字</div>
<div class="div">文字文字文字</div>
<div class="div">文字文字文字</div>
<div class="div">文字文字文字</div>
<div class="div">文字文字文字</div>
<div class="div">文字文字文字</div>
<div class="div">文字文字文字</div>
<div class="div">文字文字文字</div>
<div id="box"><!--侧边栏层-->
<div class="ss_btn">
点我
</div>
<div class="ss_content"> 内容区域 </div> </div>
<div id="mainbody"><!--主页内容-->
<p>主页的内容<p><p>主页的内容<p><p>主页的内容<p><p>主页的内容<p><p>主页的内容<p><p>主页的内容<p><p>主页的内容<p><p>主页的内容<p><p>主页的内容<p><p>主页的内容<p><p>主页的内容<p><p>主页的内容<p><p>主页的内容<p><p>主页的内容<p><p>主页的内容<p><p>主页的内容<p><p>主页的内容<p><p>主页的内容<p><p>主页的内容<p><p>主页的内容<p><p>主页的内容<p><p>主页的内容<p><p>主页的内容<p><p>主页的内容<p><p>主页的内容<p><p>主页的内容<p><p>主页的内容<p><p>主页的内容<p><p>主页的内容<p><p>主页的内容<p>
</div>
</body>
</html>

jquery插件:点击拉出的右侧滑动菜单的更多相关文章

  1. jQuery之点击弹出图标环形菜单

    <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8&quo ...

  2. html5手机端的点击弹出侧边滑动菜单代码

    效果预览:http://hovertree.com/texiao/html5/19/ 本效果适用于移动设备,可以使用手机等浏览效果. 源码下载:http://hovertree.com/h/bjaf/ ...

  3. jquery插件——点击交换元素位置(带动画效果)

    一.需求的诞生 在我们的网页或者web应用中,想要对列表中的元素进行位置调整(或者说排序)是一个常见的需求.实现方式大概就以下两种,一种是带有类似“上移”.“下移”的按钮,点击可与相邻元素交换位置,另 ...

  4. jquery插件之tab标签页或滑动门

    该插件乃本博客作者所写,目的在于提升作者的js能力,也给一些js菜鸟在使用插件时提供一些便利,老鸟就悠然地飞过吧. 此插件旨在实现目前较为流行的tab标签页或滑动门特效,在此插件中默认使用的是鼠标滑过 ...

  5. jquery插件实现鼠标经过图片右侧显示大图的效果(类似淘宝)

    这个插件的名字elevatezoom,网址为http://www.elevateweb.co.uk/image-zoom,在github上的项目首页为https://github.com/elevat ...

  6. jquery实现点击页面空白隐藏指定菜单

    注意:dmenu是一个div的class名哦 代码如下 复制代码 $('html,body').click(function(e){  if(e.target.id.indexOf("dme ...

  7. jQuery 实现点击页面其他地方隐藏菜单

    点击页面其它地方隐藏id为messageList的div 代码: $('body').delegate("#message", 'click', function(e) { var ...

  8. 15款帮助你实现响应式导航的 jQuery 插件

    对于我们大多数人来说,建立一个负责任的布局中最困难的方面是规划和导航的实现.由于没有真正经得起考验的通用解决方案,您可以使用的菜单设计风格将取决于正在建设的网站类型. 无论你正在建设什么类型的网站,在 ...

  9. 使用jQuery实现点击左右滑动切换特效

    使用jQuery实现点击左右滑动切换特效: HTML代码如下: <!--整体背景div--> <div class="warp"> <!--中间内容d ...

随机推荐

  1. (转:亲测)cnblogs博文浏览[推荐、Top、评论、关注、收藏]利器代码片段

    authour: Others(hoojo) updatetime: 2015-04-25 09:30:23 friendly link: http://www.cnblogs.com/hoojo/a ...

  2. struct和typedef struct的用法

    我首先想到的去MSDN上看看sturct到底是什么东西,虽然平时都在用,但是每次用的时候都搞不清楚到底这两个东西有什么区别,既然微软有MSDN,我们为什么不好好利用呢,下面是摘自MSDN中的一段话: ...

  3. c# 接口代码实例

    类和接口的实现 接口定义:为一组方法签名指定一个名称的方式. 类实现接口,就一定要提供接口所有方法的实现. 即使抽象类,也要全部实现,但是,它可以把接口方法声明为abstract的,从而把这个接口方法 ...

  4. linux和windows下,C/C++的sleep函数

    简介: 函数名: sleep   功 能: 执行挂起一段时间   用 法: unsigned sleep(unsigned seconds);   在VC中使用带上头文件   #include < ...

  5. 初识DSP

    初识DSP 1.TI DSP的选型主要考虑处理速度.功耗.程序存储器和数据存储器的容量.片内的资源,如定时器的数量.I/O口数量.中断数量.DMA通道数等.DSP的主要供应商有TI,ADI,Motor ...

  6. Linux下的库操作工具-nm、ar、ldd、ldconfig和ld.so

    Linux下的库操作工具-nm.ar.ldd.ldconfig和ld.so .nm [options] file 列出file中的所有符号 [option] -c 将符号转化为用户级的名字 -s 当用 ...

  7. 【模拟】Vijos P1062 迎春舞会之交谊舞

    题目链接: https://vijos.org/p/1062 题目大意: 一群男女站成一排,一男一女配对,女的只找左边第一个空闲的男生,给定前n个女生左边的额男生个数,问前n个女生到男伴之间共有几个男 ...

  8. [Silverlight]常见问题

    [Silverlight]常见问题 1. Silverlight项目是否支持ADO.NET对象? 不支持,Silverlight不支持常见的ADO.NET对象,如DataTable,DataSet,D ...

  9. Reverse Linked List II——LeetCode

    Reverse a linked list from position m to n. Do it in-place and in one-pass. For example:Given 1-> ...

  10. Vagrant 部署python开发环境

    Vagrant简介 Vagrant是一个基于Ruby的工具,用于创建和部署虚拟化开发环境.它使用Oracle的开源VirtualBox虚拟化系统,使用 Chef创建自动化虚拟环境. 在Windows下 ...