<button onclick="show()">show</button>
<button onclick="hide()">hide</button>
<script>
//创建加载对象
var obj = new loadingImg();
//显示加载图片
function show(){
obj.show();
}
//隐藏加载图片
function hide(){
obj.hide();
}
//加载图片方法(对象)
function loadingImg(mySetting){
var that = this;
if(mySetting == "" || mySetting == undefined || typeof mySetting != "object"){
mySetting = {};
}
//使用时间戳作为空间的ID
var targetID = new Date().getTime();
this.setting = {
//插入图片的容器,使用jquery的查询方式传入参数
targetConater : "",
//使用图片的地址
imgUrl : "../img/loading.gif",
//图片显示的 宽度
imgWidth : "32px",
//图片的默认样式
imgClass : "",
//生成控件的ID
"targetID" : targetID,
//显示之前的回调函数
beforeShow : function(plugin){
},
//显示之后的回调函数
afterShow : function(plugin,targetID){
}
}
this.setting = $.extend(this.setting, mySetting);
//获取屏幕的宽度
this.getScreenWidth = function(){
return document.documentElement.clientWidth;
}
//获取屏幕的高度
this.getScreenHeight = function (){
return document.documentElement.clientHeight;
}
//显示控件
this.show = function(){
$("#" + that.setting.targetID).show();
}
//隐藏控件
this.hide = function(){
$("#" + that.setting.targetID).hide();
}
this.init = function(){
//显示之前执行回调函数
if(typeof that.setting.beforeShow == "function"){
that.setting.beforeShow(that);
}
//存放字符串的变量
var targetHTML = '';
//将内容存放到指定的容器中,默认存放到body最底部
if(that.setting.targetConater != "" && this.setting.targetConater != undefined){
targetHTML = '<img src="' + that.setting.imgUrl + '" class="' + that.setting.imgClass + '" id="' + that.setting.targetID + '" style="display:none;">';
$(that.setting.targetConater).html(targetHTML);
}else{
targetHTML = '<img src="' + that.setting.imgUrl + '" class="' + that.setting.imgClass + '">';
targetHTML = '<div id="' + that.setting.targetID + '" style="display:none;position: absolute;top:50%;left: 50%;height: ' + that.getScreenHeight()+';width:'+that.getScreenWidth()+'">' + targetHTML + '</div>';
$("body").append(targetHTML);
}
//判断用户是否自定义了图片的宽度
if(that.setting.imgWidth != "" && that.setting.imgWidth.indexOf("px")>0 ){
$("#"+targetID).css("width",that.setting.imgWidth);
}
//显示之后执行回调函数
if(typeof that.setting.afterShow == "function"){
that.setting.afterShow(that,targetID);
}
}
this.init();
}
</script>
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有