用jquery向网页添加背景图片 拉伸 模糊 遮罩层 代码
方法一:手动添加
1.在body内任意位置添加html代码
<div id="web_bg" style=" position:fixed; _position:absolute; top:0; width:100%; height:100%; z-index:-2">
<img style="position:fixed;" src="http://img.bizhi.sogou.com/images/2014/07/02/701582.jpg" height="100%" width="100%" />
</div>
<div class="" id="web_bg_mask" style="height:100%; width:100%; position:fixed; _position:absolute; top:0; z-index:-1;"></div>
2.添加jquery.js文件(省略)
3.页面加载完成后渲染背景(写在html页面中)
<script>
$().ready(function() {
blurWebBackground(2);
maskWebBackground(4);
});
</script>
4.编写 blurWebBackground(); maskWebBackground();代码(写在外部js文件或本页面script标签内都可)
<script>
function blurWebBackground(blur)
{
blur = blur + "px";
$("#web_bg").css('-moz-filter', 'blur(' + blur + ')');
$("#web_bg").css('-webkit-filter', 'blur(' + blur + ')');
$("#web_bg").css('-o-filter', 'blur(' + blur + ')');
$("#web_bg").css('-ms-filter', 'blur(' + blur + ')');
$("#web_bg").css('filter', 'blur(' + blur + ')');
} function maskWebBackground(opacity)
{
$("#web_bg_mask").css('opacity', opacity / 10);
$("#web_bg_mask").css('filter', ' alpha(opacity=' + opacity * 10 + ')');
$("#web_bg_mask").css('background-color', '#333');
}
</script>
方法二:直接用jquery自动完成
1.编写ready函数,页面加载完成以后生成背景图片并处理
<script>
$().ready(function() {
addBackgroundImg();
blurWebBackground(2);
addMask();
maskWebBackground(4);
});
</script>
2.各种方法实现
function blurWebBackground(blur)
{
blur = blur + "px";
$("#web_bg").css('-moz-filter', 'blur(' + blur + ')');
$("#web_bg").css('-webkit-filter', 'blur(' + blur + ')');
$("#web_bg").css('-o-filter', 'blur(' + blur + ')');
$("#web_bg").css('-ms-filter', 'blur(' + blur + ')');
$("#web_bg").css('filter', 'blur(' + blur + ')');
} function maskWebBackground(opacity)
{
$("#web_bg_mask").css('opacity', opacity / 10);
$("#web_bg_mask").css('filter', ' alpha(opacity=' + opacity * 10 + ')');
$("#web_bg_mask").css('background-color', '#333');
}
//可以指定加载的图片名称,前提是必须在src处填好预设的你的图片存储uri地址,只需替换ImgName(图片名称)即可
function addBackgroundImg(ImgName){
var BacImg= "<div id='web_bg' style=' position:fixed; _position:absolute; top:0; width:100%; height:100%; z-index:-2'>";
BacImg += "<img style='position:fixed;' src='img/"+ImgName+".jpg' height='100%' width='100%' />";
BacImg += "</div>";
$(document.body).append(BacImg);
} //固定图片
function addBackgroundImg(){
var BacImg= "<div id='web_bg' style=' position:fixed; _position:absolute; top:0; width:100%; height:100%; z-index:-2'>";
BacImg += "<img style='position:fixed;' src='http://img.bizhi.sogou.com/images/2014/07/02/701582.jpg' height='100%' width='100%' />";
BacImg += "</div>";
$(document.body).append(BacImg);
} //也可以指定图片Uri
function addBackgroundImg(ImgUri){
var BacImg= "<div id='web_bg' style='position:fixed; _position:absolute; top:0; width:100%; height:100%; z-index:-2'>";
BacImg += "<img style='position:fixed;' src='"+ImgUri+"' height='100%' width='100%' />";
BacImg += "</div>";
$(document.body).append(BacImg);
} function addMask()
{
var BacMask = "<div id='web_bg_mask' style='height:100%; width:100%; position:fixed; _position:absolute; top:0; z-index:-1;'></div>";
$(document.body).append(BacMask);
}
用jquery向网页添加背景图片 拉伸 模糊 遮罩层 代码的更多相关文章
- jQuery实现鼠标滑过图片列表加遮罩层
这个例子实现的功能是:有一列图片列表,鼠标滑过时,将有遮罩层的另一张图盖在该图片的上方,实现鼠标hover的效果. 一.HTML代码: <div class="home-content ...
- 如何在使用itext生成pdf文档时给文档添加背景图片
这个问题我在网上搜了很久,没有找到什么解决方案,需求其实很简单,就是添加背景图片.在解决这个问题之前,我们需要了解什么是背景图片?背景图片就是位于文档最底层的图片,文字和其他内容可以浮在它的上面.这又 ...
- C#(winform)为button添加背景图片
1.既然是添加背景图片 所以这里应该使用 Button.BackgroudImage = "" ;来设置图片 而不应该使用 Button.Image = "" ...
- iOS 中 为UIView添加背景图片
创建UIImage的方法有两种: UIImage *image = [UIImageimageNamed:@"image.jpg"];//这种不释放内存,要缓存 NSString ...
- C#(winform)为button添加背景图片,并去掉各种边框
1.既然是添加背景图片 所以这里应该使用 Button.BackgroudImage = "" ;来设置图片 而不应该使用 Button.Image = "" ...
- css代码添加背景图片常用代码
css代码添加背景图片常用代码 1 背景颜色 { font-size: 16px; content: ""; display: block; width: 700px; heigh ...
- Java怎么添加背景图片
首先,导入相关的包: import java.awt.BorderLayout; import java.awt.Container; import javax.swing.ImageIcon; im ...
- [BS-29] 给UIView添加背景图片
给UIView添加背景图片 //默认情况下只能设置UIView的背景颜色,不能给UIView设置背景图片,但通过绘图知识可以做到 - (void)drawRect:(CGRect)rect { [su ...
- netbeans中给jpanl添加背景图片制定代码的理解——匿名内部类继承父类
此测试是为了仿照在netbeans中给jpanl添加背景图片的制定代码的执行过程 在JpDemo中定义了个Car类的数据类型,但在给其赋值对象时使用了匿名内部类,继承了Car类,是其子类,并重写了父类 ...
随机推荐
- ASP.NET MVC5中的数据注解
ASP.NET MVC5中Model层开发,使用的数据注解有三个作用: 数据映射(把Model层的类用EntityFramework映射成对应的表) 数据验证(在服务器端和客户端验证数据的有效性) 数 ...
- Mongodb增加权限管理
前言: 随着列式存储理念的成熟,越来越多的开发者开始接纳mongodb,hbase这类大储存的分布式列式数据库.特别是mongodb的这种快速搭建,快速使用特点,使其得到更多人的青睐.本人主要通过官 ...
- 无线通信技术协议-Zigbee 3.0
物联网的无线通信技术有:短距离的无线局域网通信技术和长距离的无线广域网通信技术. 短距离局域网通信技术有Zigbee.Wi-Fi.Bluetooth.Z-wave.6LoWPAN等. 长距离广域网通信 ...
- CCAN:C语言的模块仓库
实践中一门编程语言是否有用.好不好,不仅体现在语言本身,更在语言的生态系统:用的人多不多.社区是否活跃互帮互助.语言的相关库和框架质量如何,还有就是已有的模块的质量与数量. CPAN(Comprehe ...
- Vector3.Dot 与Vector3.Cross
Vector3.Dot(点积) : 点积的计算方式为: a·b=|a|·|b|cos<a,b>; 其中<a,b>和<b,a> 夹角不分顺序; 物理学中点积用来计算 ...
- 2014-08-01 ASP.NET中对SQLite数据库的操作——ADO.NET
今天是在吾索实习的第18天.我主要学习了如何在ASP.NET中对SQLite数据库的操作,其基本操作如下: 添加引用System.Data.SQLite.dll(PS:在网页里面任意找到适合的.NET ...
- Ubuntu 14.04 64位安装Android Studio 和 genymotion (上)
先说下,Ubuntu 上安装Android Studio真是一路坑阿,一路坑阿,加上天 朝 防火墙挡着,折腾了快一天才弄好阿 找了n多教程,md不是抄的就是转的,而且都没说清楚具体咋装阿,一个图一个 ...
- String path = request.getContextPath();这段什么用
<% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+ ...
- [React Testing] Setting up dependencies && Running tests
To write tests for our React code, we need to first install some libraries for running tests and wri ...
- linux shell 切换到ROOT用户
#!/bin/bash expect -c " set timeout 1000 spawn /bin/su - root expect \&qu ...