jq 弹窗自定义html,Jquery实现自定义弹窗示例

在项目开发中,如果我们使用javascript自带的提示对话框,感觉不怎么美观,所以我们通常都是自己定义一些对话框,这里我实现点击按钮就弹窗一个登录的窗口,点击该窗口并可以实现拖拽功能,太多文字的东西说不清楚,直接用代码说话。

这里我将HTML、CSS、Jquery代码分别贴出来

HTML部分:

弹窗

登录腾虎通行证

×

请输入用户名

请输入密码

下次自动登录忘记密码?
立即注册

可以使用一下方式登录

  • QQ
  • MSN

CSS部分代码:

*{margin:0px;padding:0px;color:#555555;}

.alter{width:50px;height:30px;margin:10px}

.box{

width:100%;

height:100%;

position:fixed;

top:0;

left:0;

background: -moz-linear-gradient(rgba(11,11,11,0.5), rgba(11,11,11,0.1)) repeat-x rgba(11,11,11,0.1);

background:-webkit-gradient(linear, 0% 0%, 0% 100%, from(rgba(11,11,11,0.1)), to(rgba(11,11,11,0.1))) repeat-x rgba(11,11,11,0.1);

z-index:100000;

display:none;

}

.box_content{

height:420px;

width:350px;

background:white;

position:fixed;

top:0;

left:0;

}

.box_content .title{

height:45px;

width:100%;

background:#EEEEEE;

line-height:45px;

overflow:hidden;

}

.title:hover{cursor: move;}

.title h3{float:left;margin-left:20px;}

.title h2{float:right;margin-right:15px;color:#999999}

.title h2:hover{color:#444444;cursor:pointer}

.box_content .content,.other{margin:20px 20px 10px 20px;overflow:hidden;font:normal 14px "宋体";}

.content table{width:99%;}

.content .inputstyle,.prompt{height:35px;width:96.5%;padding-left:10px;}

.content .inputstyle{font:bold 18px/35px "宋体";}

.content a{

text-decoration: none;

color:#1B66C7

}

.content a:hover{text-decoration: underline;}

.content table .login{

height:45px;width:101%;

border:none;

background:#4490F7;

color:#FFFFFF;

font:bold 17px "宋体";

border-radius:4px;

}

.content table .login:hover{

background:#559BFC;

}

.content .prompt{

color:#999999;

position:absolute;

line-height:38px;

}

.box_content .other{font:normal 14px "宋体";}

.other ul{

list-style:none;

margin-top:15px;

}

.other ul li{

float:left;

height:30px;

width:30px;

margin-right:15px;

border-radius:20px;

background:#1B66C7;

color:white;

text-align:center;

line-height:30px

}

Jquery代码:

$(document).ready(function(){

BoxInit.init();

});

var BoxInit={

wWidth:undefined,//浏览器宽度

wHeight:undefined,//浏览器高度

show:undefined,//显示按钮

box:undefined,//弹窗遮盖属性

boxContent:undefined,//弹窗属性

closeBox:undefined,//关闭按钮属性

loginBtn:undefined,//登录按钮属性

init:function(){

var self=this;

//获取控件对象

self.show=$("#show");

self.box=$(".box");

self.boxContent=$(".box_content");

self.closeBox=$("#close");

self.loginBtn=$("#login");

//获取浏览器可视化的宽高

self.wWidth=$(window).width();

self.wHeight=$(window).height();

//绑定显示按钮点击事件

self.show.click(function(){self.showBtn()});

//绑定关闭按钮事件

self.closeBox.click(function(){self.closes()});

//绑定登录按钮

self.loginBtn.click(function(){self.login()});

//DIV拖拽

self.dragDrop();

//调用控制提示信息

self.controlPromptInfo();

},

/**

*显示按钮

*/

showBtn:function(){

var self=this;

self.box.animate({"width":self.wWidth,"height":self.wHeight},function(){

//设置弹窗的位置

self.boxContent.animate({

"left":(self.wWidth-self.boxContent.width())/2

},function(){

$(this).animate({"top":(self.wHeight-self.boxContent.height())/2});

});

});

},

/**

*关闭按钮

*/

closes:function(){

var self=this;

self.boxContent.animate({

"top":0

},function(){

$(this).animate({"left":-(self.wWidth-self.boxContent.width())/2},function(){

self.box.animate({"width":-self.wWidth,"height":-self.wHeight});

});

});

},

/**

*登录按钮

*/

login:function(){

var self=this;

self.boxContent.animate({

"top":0

},function(){

$(this).animate({"left":-(self.wWidth-self.boxContent.width())/2},function(){

self.box.animate({"width":-self.wWidth,"height":-self.wHeight});

});

});

},

/**

*拖拽弹窗

*/

dragDrop:function(){

var self=this;

var move=false;//标识是否移动元素

var offsetX=0;//弹窗到浏览器left的宽度

var offsetY=0;//弹出到浏览器top的宽度

var title=$(".title");

//鼠标按下事件

title.mousedown(function(){

move=true;//当鼠标按在该div上的时间将move属性设置为true

offsetX=event.offsetX;//获取鼠标在当前窗口的相对偏移位置的Left值并赋值给offsetX

offsetY=event.offsetY;//获取鼠标在当前窗口的相对偏移位置的Top值并赋值给offsetY

title.css({"cursor":"move"});

}).mouseup(function(){

//当鼠标松开的时候将move属性摄hi为false

move=false;

});

$(document).mousemove(function(){

if(!move){//如果move属性不为true,就不执行下面的代码

return;

}

//move为true的时候执行下面代码

var x = event.clientX-offsetX; //event.clientX得到鼠标相对于客户端正文区域的偏移,然后减去offsetX即得到当前推拽元素相对于当前窗口的X值(减去鼠标刚开始拖动的时候在当前窗口的偏移X)

var y = event.clientY-offsetY; //event.clientY得到鼠标相对于客户端正文区域的偏移,然后减去offsetX即得到当前推拽元素相对于当前窗口的Y值(减去鼠标刚开始拖动的时候在当前窗口的偏移Y)

if(!(x<0||y<0||x>(self.wWidth-self.boxContent.width())||y>(self.wHeight-self.boxContent.height()))){

self.boxContent.css({"left":x,"top":y,"cursor":"move"});

}

});

},

/**

*控制提示信息

*/

controlPromptInfo:function(){

//遍历提示信息,并点击

$("p[class*=prompt]").each(function(){

var pro=$(this);

pro.click(function(){

//点击提示信息自身隐藏,文本框获取焦点

pro.hide().siblings("input").focus();

});

});

//遍历文本框

$("input[class*=ins]").each(function(){

var input=$(this);

//文本框失去焦点

input.blur(function(){

//如果文本框值为空

if(input.val()==""){

//显示提示信息

input.siblings(".prompt").show();

}

}).keyup(function(){//按键抬起的时候

if(input.val()==""){//如果文本框值为空

//文本框失去焦点显示提示信息

input.blur().siblings(".prompt").show();

}else{

//提示信息隐藏

input.siblings(".prompt").hide();

}

});

});

}

}

整个功能的代码都在这里了

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
jq是一种JavaScript库,它使得处理HTML文档的各种任务变得简单而高效。其中一个常见的应用就是自定义表单元素,包括radio按钮。 要使用jq自定义表单radio,我们首先需要了解radio按钮的基本原理。在HTML中,radio按钮是一组选项中的一部分,用户只能选择其中的一个选项。默认情况下,浏览器提供的radio按钮样式是标准的圆形按钮,无法自定义样式。但是使用jq,我们可以通过改变样式来自定义这些按钮,使其适应我们自己的设计需求。 首先,我们需要引入jq文件,并且在HTML文档加载完成后,使用jq选择器选中radio按钮元素。然后,我们可以使用jq的方法来添加或删除样式类,从而改变按钮的样式。 具体操作步骤如下: 1. 在HTML文档中引入jq文件: <script src="https://cdn.jsdelivr.net/npm/jquery/dist/jquery.min.js"></script> 2. 在文档加载完成后,使用jq选择器选中radio按钮元素: $(document).ready(function(){ var radioButtons = $("input[type='radio']"); }); 3. 使用jq的addClass()方法添加样式类,或者使用removeClass()方法删除样式类: $(document).ready(function(){ var radioButtons = $("input[type='radio']"); radioButtons.addClass("custom-radio"); // 添加样式类 radioButtons.removeClass("default-radio"); // 删除样式类 }); 通过给radio按钮添加自定义的样式类,我们可以根据需要来改变按钮的外观,比如改变按钮的颜色、形状、大小等。 总之,使用jq库可以方便地自定义表单radio按钮的样式,使其与我们的设计需求相匹配。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值