jquery插件整合css
A:拖拽dialog,B:進度條,C:鎖屏,D:回頂部html
A:拖拽dialog:common_drag_div.jsjquery
;(function($) {
/**
* 拖拽dialog
*/
$.drag_div = function(options) {};
$.extend($.drag_div.prototype, {
defaults: {
classes: {
"my_ui_widget_content": "my_ui_widget_content",
"ui_widget_header": "ui_widget_header",
"ui_widget_header_close": "ui_widget_header_close",
"stable_div": "stable_div",
"my_ui_widget_content_info": "my_ui_widget_content_info"
},
styles:{
my_ui_widget_content :{
'position':'absolute',
'left':'10%',
'top':'5%',
'z-index':'9991',
'border': '1px solid #c5c5c5',
'background': '#ffffff',
'padding':'10px',
'overflow-x':'hidden',
'overflow-y':'auto',
'max-width':'500px',
'_width':'expression(document.body.clientWidth > 500? "500px": "auto" )',
'max-height':'320px',
'_height':'expression(document.body.clientHeight > 320 ? "320px" : "auto")',
'filter': 'alpha(opacity=90)',
'-moz-opacity':'0.9',
'opacity': '0.9'
},
my_ui_widget_content_info:{
'overflow-y':'auto',
'border': '1px solid #c5c5c5',
'max-height':'180px',
'_height':'expression(document.body.clientHeight > 180 ? "180px" : "auto")'
},
ui_widget_header :{
'display':'inline-block',
'width':'85%',
'text-align':'center',
'padding':'5px',
'border': '1px solid #dddddd',
'background': '#e9e9e9',
'color': '#333333',
'font-size':'20px',
'font-weight': 'bold',
'cursor': 'move'
},
ui_widget_header_close:{
'display':'inline-block',
'width':'10%',
'text-align':'center',
'padding':'5px',
'border': '1px solid #c5c5c5',
'background': '#f6f6f6',
'color': '#333333',
'font-size':'20px',
'font-weight': 'bold',
'cursor': 'pointer'
},
stable_div:{
}
}
}
});
/**
* jquery封裝功能
*/
$.fn.dragDiv = function(divWrap,callback) {
if(!divWrap){
divWrap = ".my_ui_widget_content";
}
return this.each(function() {
var $divMove = $(this);//鼠標可拖拽區域
var $divWrap = divWrap ? $divMove.parents(divWrap) : $divMove;//整個移動區域
var mX = 0, mY = 0;//定義鼠標X軸Y軸
var dX = 0, dY = 0;//定義div左、上位置
var isDown = false;//mousedown標記
if(document.attachEvent) {//ie的事件監聽,拖拽div時禁止選中內容,firefox與chrome已在css中設置過-moz-user-select: none; -webkit-user-select: none;
$divMove[0].attachEvent('onselectstart', function() {
return false;
});
}
$divMove.mousedown(function(event) {
var event = event || window.event;
mX = event.clientX;
mY = event.clientY;
dX = $divWrap.offset().left;
dY = $divWrap.offset().top;
isDown = true;//鼠標拖拽啓動
});
$(document).mousemove(function(event) {
var event = event || window.event;
var x = event.clientX;//鼠標滑動時的X軸
var y = event.clientY;//鼠標滑動時的Y軸
if(isDown) {
$divWrap.css({"left": x - mX + dX, "top": y - mY + dY});//div動態位置賦值
}
});
$divMove.mouseup(function() {
isDown = false;//鼠標拖拽結束
});
//綁定關閉事件
var $closeBtn = $divWrap.find(".ui_widget_header_close");
if($closeBtn && $closeBtn.length > 0){
$closeBtn.bind("click",function(){
$divWrap.remove();
//執行回調
if(callback && typeof(callback) === "function"){
var args = [];
callback.apply(this,args);//回調函數
}
});
}
});
};
})(jQuery);web
/**
* 設置dialog數據變化html
參數:
{
"id":"xx",//dialog id
"my-ui-widget-content-info":"xx"//變動html
}
*/
var my_drag_div_operator_object = {
//數據類型
__getClass :function(object){
return Object.prototype.toString.call(object).match(/^\[object\s(.*)\]$/)[1];
},
//css對象轉style串
_getStyleStr : function(item){
var styleStr = '';
if(this.__getClass(item) == 'Object'){
for ( var p in item ){
var objVal = item[p];
styleStr += p + ":" +objVal + ";";
}
}
return styleStr;
},
_initDragDivStyle:function(){
//加載樣式,暫時style中不支持 filter ,就往head中加style FIXEDME
var defaults = $.drag_div.prototype.defaults;
var drag_style = '<style type="text/css">';
drag_style += '.'+defaults.classes.my_ui_widget_content+'{';
drag_style += this._getStyleStr(defaults.styles.my_ui_widget_content);
drag_style += '}';
drag_style += '.'+defaults.classes.ui_widget_header+'{';
drag_style += this._getStyleStr(defaults.styles.ui_widget_header);
drag_style += '}';
drag_style += '.'+defaults.classes.ui_widget_header_close+'{';
drag_style += this._getStyleStr(defaults.styles.ui_widget_header_close);
drag_style += '}';
drag_style += '.'+defaults.classes.stable_div+'{';
drag_style += this._getStyleStr(defaults.styles.stable_div);
drag_style += '}';
drag_style += '.'+defaults.classes.my_ui_widget_content_info+'{';
drag_style += this._getStyleStr(defaults.styles.my_ui_widget_content_info);
drag_style += '}';
drag_style += '</style>';
var headHtml = $("head").html();
if(!(headHtml && headHtml.indexOf('.'+defaults.classes.my_ui_widget_content) > -1)){
$("head").append(drag_style);
}
},
/**
得到drag DIV html代碼,默認html根爲body
參數:
{
"id":"xx",//id
"ui-widget-header-info": "xx",//dialog標題信息(可覆蓋)
"my-ui-widget-content-info":"xx",//dialog內容信息html(可覆蓋,常常變更的html)
"stable_div":""//dialog內容信息html((可覆蓋,不常常變更的html)
}
調用:
showDragDivHtml({"id":"xx","ui_widget_header": "合同基礎信息導入進度詳情","my_ui_widget_content_info":"處理中,請稍好。。。","stable_div":dialogProgressBar1Html});//展現拖拽
*/
showDragDivHtml:function(options){
var defaults = {"id":"","ui_widget_header": "title info is null!","my_ui_widget_content_info":"content is null!","stable_div":""};
var options = $.extend({},defaults, options);
if(options.id){
this._initDragDivStyle();//初始化樣式
var dragDivHtml = '';
dragDivHtml += '<div class="my_ui_widget_content" id="my_ui_widget_content'+options.id+'">';
dragDivHtml += '<span id="'+options.id+'" class="ui_widget_header">'+options.ui_widget_header+'</span><span class="ui_widget_header_close" title="\u5173\u95ed">x</span>';
dragDivHtml += '<div class="stable_div">'+options.stable_div+'</div>';//dialog穩定區域(暫時放進度條)
dragDivHtml += '<div class="my_ui_widget_content_info">';
dragDivHtml += options.my_ui_widget_content_info;//展現內容
dragDivHtml += '</div>';
dragDivHtml += '</div>';
$("body").prepend(dragDivHtml);
$("#"+options.id).dragDiv(".my_ui_widget_content",options.callback);
}
},
setDragDivContentInfo:function(options){
var defaults = {"id":"","my_ui_widget_content_info":"請指定內容"};
var options = $.extend(defaults, options);
if(options.id){
var my_ui_widget_content_info_obj = $("#my_ui_widget_content"+options.id+" .my_ui_widget_content_info");
my_ui_widget_content_info_obj.html(options.my_ui_widget_content_info);
try{
var my_ui_widget_content_info_scroll_height = (my_ui_widget_content_info_obj.get(0)).scrollHeight;
my_ui_widget_content_info_obj.scrollTop(my_ui_widget_content_info_scroll_height);
}
catch(err) {
console.info("setDragDivContentInfo failed,because dragDivContent has removed."+err);
}
}
},
hideDragDivContent:function(options){
var defaults = {"id":""};
var options = $.extend(defaults, options);
if(options.id){
$("#my_ui_widget_content"+options.id).remove();
}
} chrome
//alert信息
,showDragAlert:function(options){
var defaults = {"alert_info":"\u8f93\u5165\u63d0\u793a\u4fe1\u606f"};
var options = $.extend(defaults, options);
var _rootEl=document.compatMode=="CSS1Compat"?document.documentElement:document.body;
var top = "30%";
if(_rootEl){
top = _rootEl.scrollTop + _rootEl.clientHeight/2 - _rootEl.clientHeight/4 ;
top += "px";
}
var my_alert_html = '';
my_alert_html += '<div id="';
if(options.id){
my_alert_html += options.id;
}
my_alert_html += '" class="my_alert_info" style="border:1px solid #c5c5c5;background:#ffffff;padding:5px;width:210px;heigth:200px;position:absolute;left:50%;top:'+top+';z-index:9991">';
my_alert_html += ' <span class="my_alert_info_head" style="display:inline-block;width:90%;text-align:left;padding:3px;border: 1px solid #dddddd;background: #e9e9e9;color: #333333;font-weight: bold;cursor: move;">';
my_alert_html += ' \u7f51\u9875\u4fe1\u606f';
my_alert_html += ' </span>';
my_alert_html += ' <span class="ui_widget_header_close" title="\u5173\u95ed" style="display:inline-block;width:10%;text-align:center;border:1px solid #c5c5c5;background:#e9e9e9;color:#333333;font-weight:bold;cursor:pointer;padding:3px;">X</span>';
my_alert_html += ' <div class="alert_info" style="margin-top:5px;padding:3px;">';
my_alert_html += options.alert_info;
my_alert_html += ' </div>';
my_alert_html += ' <div class="ui_widget_header_close" style="margin-top:10px;border:1px solid #c5c5c5;padding:3px;cursor:pointer;margin-left:30%;text-align:center;width:50px;">\u786e\u5b9a</div>';
my_alert_html += '</div>';
$("body").prepend(my_alert_html);
$(".my_alert_info_head").dragDiv(".my_alert_info",function(){
});
}
,hideDragAlert:function(options){
$(".my_alert_info").remove();
}
};express
document.onkeydown = function(e) {
//回車關閉my_alert_info
if($(".my_alert_info").length > 0){
var ev = (typeof event!= 'undefined') ? window.event : e;
if(ev.keyCode == 13) {
$(".my_alert_info").remove();
}
}
}app
B:進度條:common_plug_progressbar.jsjquery插件
/**
* 仿jquery ui progressbar,div自動轉進度條
* 使用:引入本插件
*/
;(function($) {
/**
* 進度條構造
*
調用:
<div id="myprogressbarxxx" style="height:20px;width:100px;"></div>
$( function() {
$("#myprogressbarxxx").progressbar();//初始化進度
$("#myprogressbarxxx").setProgressbarValue(2);//設置進度比0-100
var per = $("#myprogressbarxxx").getProgressbarValue();//得到進度值
alert(per);
} );
*/
var progressbar = function(this_progressbar,options) {
return this._init_progressbar(this_progressbar,options);
};
$.extend(progressbar.prototype, {
defaults: {
classes: {
"ui_progressbar_content": "ui_progressbar_content",
"ui_progressbar_percent": "ui_progressbar_percent",
"ui_progressbar": "ui_progressbar",
"ui_out_progressbar_percent": "ui_out_progressbar_percent"
},
styles:{
ui_progressbar_content :{
"border": "1px solid #c5c5c5",
"background": "#ffffff",
"color": "#333333",
"display":"inline"
},
ui_progressbar :{
"position":"relative",
"height": "100%",
"cursor":"pointer",
"background": "#e9e9e9",
"overflow": "hidden"
},
ui_progressbar_percent:{
"position":"absolute",
"right":"3px"
},
ui_out_progressbar_percent:{
}
},
min: 0,
max: 100,
value: 0
},
//構造html
_init_progressbar: function(this_progressbar,options) {
var options = $.extend({},this.defaults, options);
var per_info = options.value+"%";
var this_ui_progressbar_content = $(this_progressbar).css(options.styles.ui_progressbar_content).attr("title",per_info);
var this_ui_progressbar_percent = $("<div>").addClass(options.classes.ui_progressbar_percent).css(options.styles.ui_progressbar_percent).html(per_info);
var this_ui_progressbar = $("<div>").addClass(options.classes.ui_progressbar).css(options.styles.ui_progressbar).css({"width":per_info});
this_ui_progressbar_percent.appendTo(this_ui_progressbar);
this_ui_progressbar.appendTo(this_ui_progressbar_content);
return this_ui_progressbar_content;
}
});
//包裝jquery div進度對象
$.fn.progressbar = $.prototype.progressbar = function(options) {
return this.each(function() {
if (this.tagName. toLowerCase() == "div"){
new progressbar(this, options);//要的話存在data中
}
});
};
/**
* jquery 設置/得到進度值
*
* 調用:
* $("#myprogressbarxxx").setProgressbarValue(2);//設置進度比0-100
* var per = $("#myprogressbarxxx").getProgressbarValue();//得到進度值
alert(per);
*
*/
$.fn.extend({
//設置進度值
'setProgressbarValue':function(value){
if(value > 100){
value = 100;
}
var per_info = value+"%";
$(this).attr("title",per_info);
$(this).find("."+progressbar.prototype.defaults.classes.ui_progressbar_percent).html(per_info);
$(this).find("."+progressbar.prototype.defaults.classes.ui_progressbar).css({"width":per_info});
$(this).next("."+progressbar.prototype.defaults.classes.ui_out_progressbar_percent).html(per_info);
},
//得到進度值
'getProgressbarValue':function(value){
return $(this).attr("title");
}
});
/**
* 精確計算
*/
var MY_MATH = {
//除法
_accDiv:function(arg1, arg2) {
var t1 = 0, t2 = 0, r1, r2;
try {
t1 = arg1.toString().split(".")[1].length;
}
catch (e) {
}
try {
t2 = arg2.toString().split(".")[1].length;
}
catch (e) {
}
with (Math) {
r1 = Number(arg1.toString().replace(".", ""));
r2 = Number(arg2.toString().replace(".", ""));
return (r1 / r2) * pow(10, t2 - t1);
}
}
};
/**
* 1.得到進度條html
* 2.啓動進度條
*
* 調用:
* var my_progressbar_operator = new $.my_progressbar_operator ();
* var html = my_progressbar_operator.getProgressBarInstance({});
* my_progressbar_operator.startProgressBar({"id":"xx"});
*
*/
$.my_progressbar_operator = function(options) { };
$.extend($.my_progressbar_operator.prototype, {
//數據類型
__getClass :function(object){
return Object.prototype.toString.call(object).match(/^\[object\s(.*)\]$/)[1];
},
//css對象轉style串
_getStyleStr : function(item){
var styleStr = '';
if(this.__getClass(item) == 'Object'){
for ( var p in item ){
var objVal = item[p];
styleStr += p + ":" +objVal + ";";
}
}
return styleStr;
},
/**
* 構建progressbar html
*
* 參數說明:
{
id:"",//進度id(必須指定)
value: 0,//進度完成比例(可覆蓋)
styles:{
width:"200px",//進度條寬(可覆蓋)
height:"20px"//進圖調高度(可覆蓋)
}
};
*/
_construct_progressbar_html:function(outer_options){
var defaults = progressbar.prototype.defaults;
var $this_ui_progressbar_content = $.extend(defaults.styles.ui_progressbar_content, outer_options.styles);
var ui_progressbar_content_style = this._getStyleStr($this_ui_progressbar_content);
var ui_progressbar_percent_style = this._getStyleStr(defaults.styles.ui_progressbar_percent);
var ui_progressbar_style = this._getStyleStr(defaults.styles.ui_progressbar);
var pro_html = '<div class="'+defaults.classes.ui_progressbar_content+'" id= "'+outer_options.id+'" title="'+outer_options.value+'%" style="'+ui_progressbar_content_style+'">';
pro_html += '<div class="'+defaults.classes.ui_progressbar+'" style="'+ui_progressbar_style+'width:'+outer_options.value+'%">';
pro_html += '<div class="'+defaults.classes.ui_progressbar_percent+'" style="'+ui_progressbar_percent_style+'">'+outer_options.value+'%</div>';
pro_html += '</div>';
pro_html += '</div>';
pro_html += '<span class="'+defaults.classes.ui_out_progressbar_percent+'">'+outer_options.value+'%</span>';
//console.info("pro_html is:"+pro_html);
return pro_html;
},
/**
* 構造進度html
*
參數說明:
defaults = {
id:"",//進度id(必須)
value: 0,//進度完成比例(可覆蓋)
styles:{
width:"200px",//進度條寬(可覆蓋)
height:"20px"//進圖調高度(可覆蓋)
}
};
*
*/
getProgressBarInstance:function(options){
var defaults = {
id:"",
value: 0,
styles:{
width:"200px",
height:"20px"
}
};
var options = $.extend({},defaults, options);
if(!options.id){
alert("init progress need args : id !");
return "";
}
return this._construct_progressbar_html(options);
},
/**
* 開啓進度
*
* 參數說明:
defaults = {
id:"",//進度id(必須)
start_value: 0,//起始值(可覆蓋)
end_value:100,//完成值(可覆蓋)
time_cost:10//耗時(s)(可覆蓋)
};
*/
startProgressBar: function (options){
var defaults = {
id:"",
start_value: 0,
end_value:100,
time_cost:10
};
var options = $.extend({},defaults, options);
if(!options.id){
alert("startProgressBar need args : id !");
return;
}
var distance_value = Number(options.end_value) - Number(options.start_value);
var increase_per = MY_MATH._accDiv(distance_value,Number(options.time_cost));//每秒的增量
var progress_init = Number(options.start_value);//起始值
var interval_temp = setInterval(function(){
//
if(progress_init >= 100){
if(interval_temp){
window.clearInterval(interval_temp);
}
progress_init = 100;
}else{
progress_init = progress_init + increase_per;
}
progress_init = Math.round(progress_init*100)/100;
$("#"+options.id).setProgressbarValue(progress_init);//設置進度
//console.info("progress bar id:"+progress_init+" is:"+progress_init);
//
},1000);
}
});
})(jQuery);
ide
C:鎖屏:common_lock_screen.js函數
/**
* 鎖屏
*/
;(function($) {
$.lock_screen = function(options) {};
$.extend($.lock_screen.prototype, {
defaults: {
classes: {
"ie_fixed_lock_screen": "ie_fixed_lock_screen",
"ie_fixed_lock_screen_center_position": "ie_fixed_lock_screen_center_position"
},
styles:{
ie_fixed_lock_screen :{
'display':'none',
'z-index':'9990',
'width':'100%',
'height':'100%',
'filter': 'alpha(opacity=50)',
'-moz-opacity':'0.5',
'opacity': '0.5',
'background':'#DDD',
'_position': 'absolute',
'_clear': 'both',
'_top':'expression(eval(document.compatMode && document.compatMode=="CSS1Compat") ? documentElement.scrollTop +(documentElement.clientHeight-this.clientHeight) - 8 : document.body.scrollTop +(document.body.clientHeight-this.clientHeight) - 8)'
}
,ie_fixed_lock_screen_center_position:{
'position':'absolute',
'top':'40%',
'left':'30%',
'scroll':'auto'
}
}
}
});
})(jQuery);
var my_lock_screen_operator_object = {
//數據類型
__getClass :function(object){
return Object.prototype.toString.call(object).match(/^\[object\s(.*)\]$/)[1];
},
//css對象轉style串
_getStyleStr : function(item){
var styleStr = '';
if(this.__getClass(item) == 'Object'){
for ( var p in item ){
var objVal = item[p];
styleStr += p + ":" +objVal + ";";
}
}
return styleStr;
},
_init_lock_screen_style:function(){
//加載樣式,暫時style中不支持 filter ,就往head中加style FIXEDME
var defaults = $.lock_screen.prototype.defaults;
var drag_style = '<style type="text/css">';
drag_style += '.'+defaults.classes.ie_fixed_lock_screen+'{';
drag_style += this._getStyleStr(defaults.styles.ie_fixed_lock_screen);
drag_style += '}';
drag_style += '.'+defaults.classes.ie_fixed_lock_screen_center_position+'{';
drag_style += this._getStyleStr(defaults.styles.ie_fixed_lock_screen_center_position);
drag_style += '}';
drag_style += '</style>';
var headHtml = $("head").html();
if(!(headHtml && headHtml.indexOf('.'+defaults.classes.my_ui_widget_content) > -1)){
$("head").append(drag_style);
//console.info("dary_style:"+drag_style);
}
},
showLockScreen:function(){
this._init_lock_screen_style();
$("body").append('<div class="ie_fixed_lock_screen"><div class="ie_fixed_lock_screen_center_position">\u5904\u7406\u4e2d\uff0c\u8bf7\u7a0d\u540e\u3002\u3002\u3002</div></div>');
$(".ie_fixed_lock_screen").show();
},
setLockScreenInfo:function(lockScreenInfo){
if(lockScreenInfo){
$(".ie_fixed_lock_screen_center_position").html(lockScreenInfo);
}
},
hideLockScreen:function(){
$(".ie_fixed_lock_screen").remove();
}
}
D:回頂部:common_scroll.js
/** *回到頂部 auto scroll 頁面引入生效 */ ;(function($) { /** * dialog配置 */ $.auto_scroll = function(options) {}; $.extend($.auto_scroll.prototype, { defaults: { classes: { "scroll_fixed_": "scroll_fixed_", "ie_scroll_fixed_": "ie_scroll_fixed_", "x_scroll_goto_top": "x_scroll_goto_top" }, styles:{ scroll_fixed_ :{ 'position':'fixed', 'right':'8px', 'bottom':'8px', 'width':'30px', 'height':'30px', 'cursor':'pointer', 'border-radius':'2px' }, ie_scroll_fixed_ :{ '_position': 'absolute', '_clear': 'both', '_top':'expression(eval(document.compatMode && document.compatMode=="CSS1Compat") ? documentElement.scrollTop +(documentElement.clientHeight-this.clientHeight) - 8 : document.body.scrollTop +(document.body.clientHeight-this.clientHeight) - 8)' }, x_scroll_goto_top:{ 'border': '1px solid #DDD', 'font':'25px', 'color':'#4e736e', 'line-height':'30px', 'font-color':'#DBF1EE', 'text-align':'center' } } } }); })(jQuery); var my_scroll_operator_object = { //數據類型 __getClass :function(object){ return Object.prototype.toString.call(object).match(/^\[object\s(.*)\]$/)[1]; }, //css對象轉style串 _getStyleStr : function(item){ var styleStr = ''; if(this.__getClass(item) == 'Object'){ for ( var p in item ){ var objVal = item[p]; styleStr += p + ":" +objVal + ";"; } } return styleStr; }, _initScrollStyle:function(){ //加載樣式,暫時style中不支持 filter ,就往head中加style FIXEDME var defaults = $.auto_scroll.prototype.defaults; var drag_style = '<style type="text/css">'; drag_style += '.'+defaults.classes.scroll_fixed_+'{'; drag_style += this._getStyleStr(defaults.styles.scroll_fixed_); drag_style += '}'; drag_style += '.'+defaults.classes.ie_scroll_fixed_+'{'; drag_style += this._getStyleStr(defaults.styles.ie_scroll_fixed_); drag_style += '}'; drag_style += '.'+defaults.classes.x_scroll_goto_top+'{'; drag_style += this._getStyleStr(defaults.styles.x_scroll_goto_top); drag_style += '}'; drag_style += '</style>'; var headHtml = $("head").html(); if(!(headHtml && headHtml.indexOf('.'+defaults.classes.scroll_fixed_) > -1)){ $("head").append(drag_style); } } } $(document).ready(function () { my_scroll_operator_object._initScrollStyle(); $("body").append('<div class="scroll_fixed_ ie_scroll_fixed_ x_scroll_goto_top" title="\u56de\u9876\u90e8">\u2191</div>'); $(window).scroll(function() { var sctop = $(document).scrollTop(); if(sctop > 10){ $(".x_scroll_goto_top").fadeIn("middle"); }else{ $(".x_scroll_goto_top").fadeOut("middle"); } }); //回到頂部 $('.x_scroll_goto_top').click(function(){ $('html, body').animate({scrollTop:0}, 'middle'); }); });