/* * jquery fixed plugins 1.5.1 * author: * url: * data * * update log: * * status date name version bug-description * ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ * created 2012-08-15 ru 1.0 none * modified 2012-09-02 ru 1.4.1 修复了webkit内核浏览器右边浮动有一定距离的bug(负外边距),增加了悬浮靠边的定位、是否显示关闭按钮、是否垂直居中定位 * modified 2013-01-02 ru 1.5.1 增加了垂直方向的位置;把核心函数(关闭、展开、定位、最小化)重构,修复了webkit内核浏览器右边浮动最小化时没有显示出来 * ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ ;(function($){ $.fn.fix = function(options){ var defaults = { position : "left", //悬浮位置 - left或right horizontal : 0, //水平方向的位置 - 默认为数字 vertical : null, //垂直方向的位置 - 默认为null halftop : false, //是否垂直居中位置 minstatue : false, //是否最小化 hideclosebtn : false, //是否隐藏关闭按钮 skin : "gray", //风格皮肤 showbtnwidth : 28, //show_btn_width contentboxwidth : 154, //side_content_width durationtime : 1000 //完成时间 } var options = $.extend(defaults, options); this.each(function(){ //获取对象 var thisbox = $(this), closebtn = thisbox.find(".close_btn"), show_btn = thisbox.find(".show_btn"), contentbox = thisbox.find(".content_box"), sidelist = thisbox.find(".side_list") ; //设置内容的高度 thisbox.height( contentbox.height() ); //最小化 if(options.minstatue){ show_btn.show(); if(options.position=="left"){ contentbox.css({ left: -options.contentboxwidth }); }else if(options.position=="right"){ contentbox.css({ right: -options.contentboxwidth }); } thisbox.css({ width: options.showbtnwidth }); } //皮肤控制 if(options.skin) thisbox.addclass("skin_" + options.skin); //隐藏关闭按钮 if(options.hideclosebtn) closebtn.css("display", "none"); //定位 var boxtop = null, defaulttop = thisbox.offset().top, //对象的默认top halftop = ($(window).height() - thisbox.height())/2 //垂直居中时候的top ; if(options.vertical == null){ boxtop = defaulttop; }else { boxtop = options.vertical; } if( options.halftop ) { boxtop = halftop; } thisbox.css(options.position, options.horizontal); thisbox.css("top", boxtop); //核心scroll事件 $(window).bind("scroll",function(){ var offsettop = boxtop + $(window).scrolltop() + "px"; thisbox.animate({ top: offsettop },{ duration: options.durationtime, queue: false //此动画将不进入动画队列 }); }); //关闭 closebtn.bind("click",function(){ show_btn.show(); if(options.position=="left"){ contentbox.animate({left: -options.contentboxwidth},"fast"); }else if(options.position=="right"){ contentbox.animate({right: -options.contentboxwidth },"fast"); } thisbox.animate({width: options.showbtnwidth },"fast"); }); //展开 show_btn.bind("click", function() { if(options.position=="left"){ contentbox.animate({left: 0},"fast"); } else if(options.position=="right"){ contentbox.animate({right: 0},"fast"); } thisbox.animate({width: options.contentboxwidth },"fast"); show_btn.hide(); }); }); //end this.each }; })(jquery);