jQuery技术

JQuery 技巧(转)(2)

字号+ 作者:H5之家 来源:H5之家 2015-11-12 16:35 我要评论( )

view plaincopy to clipboardprint? !-- 可以先定义一个class,比如blur -- form action="" divlabel for="search"Search:/label input type="text" value="" title="Company name or ticker" / input type="submit

view plaincopy to clipboardprint?
<!-- 可以先定义一个class,比如blur -->
<form action="">
<div><label for="search">Search:</label>
<input type="text" value="" title="Company name or ticker" />
<input type="submit" value="Go" />
</div>
</form>
<!-- 可以先定义一个class,比如blur -->
<form action="">
<div><label for="search">Search:</label>
<input type="text" value="" title="Company name or ticker" />
<input type="submit" value="Go" />
</div>
</form>

当前页弹出层
via Simple jQuery

view plaincopy to clipboardprint?
$(document).ready(function() {

//select all the a tag with name equal to modal
$('a[name=modal]').click(function(e) {
//Cancel the link behavior
e.preventDefault();
//Get the A tag
var id = $(this).attr('href');

//Get the screen height and width
var maskHeight = $(document).height();
var maskWidth = $(window).width();

//Set heigth and width to mask to fill up the whole screen
$('#mask').css({'width':maskWidth,'height':maskHeight});

//transition effect
$('#mask').fadeIn(1000);
$('#mask').fadeTo("slow",0.8);

//Get the window height and width
var winH = $(window).height();
var winW = $(window).width();

//Set the popup window to center
$(id).css('top', winH/2-$(id).height()/2);
$(id).css('left', winW/2-$(id).width()/2);

//transition effect
$(id).fadeIn(2000);

});

//if close button is clicked
$('.window .close').click(function (e) {
//Cancel the link behavior
e.preventDefault();
$('#mask, .window').hide();
});

//if mask is clicked
$('#mask').click(function () {
$(this).hide();
$('.window').hide();
});

});
$(document).ready(function() {

//select all the a tag with name equal to modal
$('a[name=modal]').click(function(e) {
//Cancel the link behavior
e.preventDefault();
//Get the A tag
var id = $(this).attr('href');

//Get the screen height and width
var maskHeight = $(document).height();
var maskWidth = $(window).width();

//Set heigth and width to mask to fill up the whole screen
$('#mask').css({'width':maskWidth,'height':maskHeight});

//transition effect
$('#mask').fadeIn(1000);
$('#mask').fadeTo("slow",0.8);

//Get the window height and width
var winH = $(window).height();
var winW = $(window).width();

//Set the popup window to center
$(id).css('top', winH/2-$(id).height()/2);
$(id).css('left', winW/2-$(id).width()/2);

//transition effect
$(id).fadeIn(2000);

});

//if close button is clicked
$('.window .close').click(function (e) {
//Cancel the link behavior
e.preventDefault();
$('#mask, .window').hide();
});

//if mask is clicked
$('#mask').click(function () {
$(this).hide();
$('.window').hide();
});

});

使用方法

view plaincopy to clipboardprint?
<!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" xml:lang="en" lang="en">
<head>
<mce:script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" mce_src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></mce:script>
<title>Sandbox</title>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<mce:style type="text/css" media="screen"><!--
body { background-color: #fff; font: 16px Helvetica, Arial; color: #fff; }
#mask {
left:0;
top:0;
position:absolute;
z-index:9000;
background-color:#000;
display:none;
}

#boxes .window {
position:fixed;
width:440px;
height:200px;
display:none;
z-index:9999;
padding:20px;
}

/* Customize your modal window here, you can add background image too */
#boxes #dialog {
width:375px;
height:203px;
}
--></mce:style><style type="text/css" media="screen" mce_bogus="1">body { background-color: #fff; font: 16px Helvetica, Arial; color: #fff; }
#mask {
left:0;
top:0;
position:absolute;
z-index:9000;
background-color:#000;
display:none;
}

#boxes .window {
position:fixed;
width:440px;
height:200px;
display:none;
z-index:9999;
padding:20px;
}

/* Customize your modal window here, you can add background image too */
#boxes #dialog {
width:375px;
height:203px;
}</style>
</head>
<body>
<p><a href="#dialog" mce_href="#dialog">Simple Window Modal</a></p>
<div>
<!-- #customize your modal window here -->
<div>
<b>Testing of Modal Window</b> |
<!-- close button is defined as close class -->
<a href="#" mce_href="#">Close it</a>
</div>
<!-- Do not remove div#mask, because you'll need it to fill the whole screen -->
<div></div>
</div>
</body>
</html>
<!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" xml:lang="en" lang="en">
<head>
<mce:script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" mce_src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></mce:script>
<title>Sandbox</title>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<mce:style type="text/css" media="screen"><!--
body { background-color: #fff; font: 16px Helvetica, Arial; color: #fff; }
#mask {
left:0;
top:0;
position:absolute;
z-index:9000;
background-color:#000;
display:none;
}

#boxes .window {
position:fixed;
width:440px;
height:200px;
display:none;
z-index:9999;
padding:20px;
}

 

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

相关文章
  • 7个有用的jQuery小技巧

    7个有用的jQuery小技巧

    2016-02-26 13:02

  • jQuery制作select双向选择列表

    jQuery制作select双向选择列表

    2016-02-26 11:00

  • 全面详细的jQuery常见开发技巧手册

    全面详细的jQuery常见开发技巧手册

    2016-02-26 10:02

  • 强大的jQuery移动插件Top 10

    强大的jQuery移动插件Top 10

    2016-02-25 09:05

网友点评
e