jquery插件:点击拉出的右侧滑动菜单
来源:互联网 发布:淘宝刷单假后台怎么看 编辑:程序博客网 时间:2024/04/30 15:39
初写jquery插件,就是一个停留在页面右侧的滑动菜单,点击可以拉出,带回调函数。宽高位置可以参数指定。插件代码如下:
(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)
<!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插件:点击拉出的右侧滑动菜单
- android 左右侧滑菜单(点击+左右滑动)一
- android 左右侧滑菜单(点击+左右滑动)
- 右侧滑动悬浮【jquery】
- jquery右侧菜单
- 点击左侧菜单在右侧弹出相应的内容
- JQuery 从右侧向左滑动
- appframework 左侧和右侧点击滑动显示
- 后台左侧菜单点击上下滑动显示jquery
- jQuery 树形菜单(竖向点击和横向滑动)
- DrawerLayout 左侧 右侧 点击 侧滑菜单
- 左侧菜单,点击右侧弹出内容
- MGSwipeTableCell的使用(UItabelCell 滑动拉出多个按钮)
- JQuery的animate()实现菜单滑动
- jQuery右侧弹出全屏覆盖菜单
- jQuery右侧弹出全屏覆盖菜单
- jQuery滑动导航菜单
- JQuery简单实现菜单的点击效果
- 用命令实现Win7远程桌面关机和重启
- html与jsp指定编码的方式不一样的
- [LeetCode] Sqrt(x)
- Android有用代码(一)
- ACM 问题分类
- jquery插件:点击拉出的右侧滑动菜单
- httpClient 连接 https + 证书连接
- 排序算法之希尔排序
- 小试牛刀--自己小小的网站
- 浮点数的存储
- [LeetCode] Plus One
- 今时今日,C还适合当下之所需么?
- jni返回结构体数组
- 扇入扇出的概念