方法一:手动添加

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向网页添加背景图片 拉伸 模糊 遮罩层 代码的更多相关文章

  1. jQuery实现鼠标滑过图片列表加遮罩层

    这个例子实现的功能是:有一列图片列表,鼠标滑过时,将有遮罩层的另一张图盖在该图片的上方,实现鼠标hover的效果. 一.HTML代码: <div class="home-content ...

  2. 如何在使用itext生成pdf文档时给文档添加背景图片

    这个问题我在网上搜了很久,没有找到什么解决方案,需求其实很简单,就是添加背景图片.在解决这个问题之前,我们需要了解什么是背景图片?背景图片就是位于文档最底层的图片,文字和其他内容可以浮在它的上面.这又 ...

  3. C#(winform)为button添加背景图片

    1.既然是添加背景图片 所以这里应该使用 Button.BackgroudImage = "" ;来设置图片 而不应该使用  Button.Image = "" ...

  4. iOS 中 为UIView添加背景图片

    创建UIImage的方法有两种: UIImage *image = [UIImageimageNamed:@"image.jpg"];//这种不释放内存,要缓存 NSString ...

  5. C#(winform)为button添加背景图片,并去掉各种边框

    1.既然是添加背景图片 所以这里应该使用 Button.BackgroudImage = "" ;来设置图片 而不应该使用  Button.Image = "" ...

  6. css代码添加背景图片常用代码

    css代码添加背景图片常用代码 1 背景颜色 { font-size: 16px; content: ""; display: block; width: 700px; heigh ...

  7. Java怎么添加背景图片

    首先,导入相关的包: import java.awt.BorderLayout; import java.awt.Container; import javax.swing.ImageIcon; im ...

  8. [BS-29] 给UIView添加背景图片

    给UIView添加背景图片 //默认情况下只能设置UIView的背景颜色,不能给UIView设置背景图片,但通过绘图知识可以做到 - (void)drawRect:(CGRect)rect { [su ...

  9. netbeans中给jpanl添加背景图片制定代码的理解——匿名内部类继承父类

    此测试是为了仿照在netbeans中给jpanl添加背景图片的制定代码的执行过程 在JpDemo中定义了个Car类的数据类型,但在给其赋值对象时使用了匿名内部类,继承了Car类,是其子类,并重写了父类 ...

随机推荐

  1. <Pro .NET MVC4> 三大工具之依赖注入神器——Ninject

    这篇内容是对<Pro .NET MVC4>一书中关于Ninject介绍的总结. Ninject是.NET MVC的一款开源的依赖注入工具. 使用场景:当MVC项目中使用了依赖注入技术来给程 ...

  2. NET Core驱动已出,支持EF Core

    NET Core驱动已出,支持EF Core 千呼万唤始出来MySQL官方.NET Core驱动已出,支持EF Core. 昨天MySQL官方已经发布了.NET Core 驱动,目前还是预览版,不过功 ...

  3. yarn资源调度(网络搜集)

    本文转自:http://www.itweet.cn/2015/07/24/yarn-resources-manager-allocation/ Hadoop YARN同时支持内存和CPU两种资源的调度 ...

  4. iOS 数据库操作(使用FMDB)

    iOS 数据库操作(使用FMDB)   iOS中原生的SQLite API在使用上相当不友好,在使用时,非常不便.于是,就出现了一系列将SQLite API进行封装的库,例如FMDB.Plausibl ...

  5. 宏定义 button 方法 --备

    定义 #define BARBUTTON(TITLE, SELECTOR) [[[UIBarButtonItem alloc] initWithTitle:TITLE style:UIBarButto ...

  6. android使用apktool反编译出现Input file (d:\t) was not found or was not readable

    Input file (d:\t) was not found or was not readable 出现这个错误是因为apktool压缩包下载错误,我是下成首页的那个压缩包了 正确下载地址:htt ...

  7. nodejs定时任务node-schedule

    1:使用npm安装node-schedule模块 npm install node-schedule (1)每隔5分钟执行一次: var schedule = require('node-schedu ...

  8. android ftp案例分析

    使用方法: FTPClient client = new FTPClient(); client.connect("ftp.host.com", 8021); client.log ...

  9. Android中的手势

    Android对两种手势行为提供了支持:1.对于第一种手势行为而言,Android提供了手势检测,并为手势检测提供了相应的监听器.2.对于第二种手势行为,Android允许开发者添加手势,并提供了相应 ...

  10. Altium Designer多图纸原理图设计方法探讨

    1 图纸结构 包括层次式图纸的连接关系是纵向的,也就是某一层次的图纸只能和相邻的上级或下级有关系,另一种即扁平式图纸的连接关系是横向的,任何两张图纸之间都可以建立信号连接. 2 网络连接方式 Alti ...