设置为fixed属性,背景相对于屏幕窗口固定,然后如果有一张全屏的图片,再来一张全屏的图片,就可以看到与平时滚动屏幕不同的切换图片。代码
CSS部分:

html, body,.content{
height: 100%;
}
h2, body { margin: 0;}
.fixed-bg {
position: relative;
background-size: cover;
background-attachment: fixed;
height: 100%;
background-position: center center;
}
.bg-1 {
background-image: url("images/cd-background-1.jpg");
}
.container {
padding: 23% 1%;
background-color: #C7ABAB;
height: 100%;
}
.bg-2 {
background-image: url("images/cd-background-2.jpg");
}

HTML部分:

<div class="main content">
<div class="fixed-bg bg-1">
<h2>此处是图片</h2>
</div>
<div class="fixed-bg bg-2">
<h2>又一张图片</h2>
</div>
</div>

由此可以想到:如果图片之间加上内容 ,就会是比较新鲜的滚动方式:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style type="text/css">
html, body,.content{
height: 100%;
}
h2, body { margin: 0;}
.fixed-bg {
position: relative;
background-size: cover;
background-attachment: fixed;
height: 100%;
background-position: center center;
}
.bg-1 {
background-image: url("images/cd-background-1.jpg");
}
.container { padding: 23% 1%;
background-color: #C7ABAB;
height: 100%;}
.bg-2 {
background-image: url("images/cd-background-2.jpg");
} </style> </head>
<body>
<div class="main content">
<div class="fixed-bg bg-1">
<h2>此处是图片</h2>
</div>
<div class="scrolling-bg">
<div class="container">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Dolore incidunt suscipit similique, dolor corrupti cumque qui consectetur autem laborum fuga quas ipsam doloribus sequi, mollitia, repellendus sapiente repudiandae labore rerum amet culpa inventore, modi non. Illo quod repellendus alias? Cum rem doloremque adipisci accusantium? Saepe, necessitatibus!</p>
</div>
</div> <div class="fixed-bg bg-2">
<h2>又一张图片</h2>
</div>
<div class="scrolling-bg">
<div class="container">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Dolore incidunt suscipit similique, dolor corrupti cumque qui consectetur autem laborum fuga quas ipsam doloribus sequi, mollitia, repellendus sapiente repudiandae labore rerum amet culpa inventore, modi non. Illo quod repellendus alias? Cum rem doloremque adipisci accusantium? Saepe, necessitatibus!</p>
</div>
</div>
</div>
</body>
</html>

background-attachment:fixed应用的更多相关文章

  1. [转]滚动视差?CSS 不在话下/background attachment

      何为滚动视差 视差滚动(Parallax Scrolling)是指让多层背景以不同的速度移动,形成立体的运动效果,带来非常出色的视觉体验. 作为网页设计的热点趋势,越来越多的网站应用了这项技术. ...

  2. 一行代码轻松搞定各种IE兼容问题,IE6,IE7,IE8,IE9,IE10

    在网站开发中不免因为各种兼容问题苦恼,针对兼容问题,其实IE给出了解决方案Google也给出了解决方案百度也应用了这种方案去解决IE的兼容问题? 百度源代码如下: <!Doctype html& ...

  3. background属性的学习整理转述

    前言:这是笔者学习之后自己的理解与整理.如果有错误或者疑问的地方,请大家指正,我会持续更新! background我们一般用到的的属性有: background-attachment:背景(图片)是否 ...

  4. css 背景 background

    前言:这是笔者学习之后自己的理解与整理.如果有错误或者疑问的地方,请大家指正,我会持续更新! background我们一般用到的的属性有: background-attachment:背景(图片)是否 ...

  5. CSS3详解:background

    CSS3对于background做了一些修改,最明显的一个就是采用设置多背景,不但添加了4个新属性,并且还对目前的属性进行了调整增强. 1.多个背景图片 在css3里面,你可以再一个标签元素里应用多个 ...

  6. absolute vs fixed

    <!DOCTYPE html> <html> <head> <title>absolute和fixed的区别</title> <sty ...

  7. 神奇的background

    background:url() fixed ....  可以实现页面向下滚动时背景图片 保持位置不变   感觉好像背景在随鼠标滚动而滚动一样

  8. CSS3中background属性的调整

    CSS3对于background做了一些修改,最明显的一个就是采用设置多背景,不但添加了4个新属性,并且还对目前的属性进行了调整增强. 1.多个背景图片 在css3里面,你可以再一个标签元素里应用多个 ...

  9. CSS--background

    它的组合写法: background-color, background-image, background-repeat,backgroundattachment, background-posit ...

  10. CSS 笔记一(Selectors/ Backgrounds/ Borders/ Margins/ Padding/ Height and Width)

    Selectors/ Backgrounds/ Borders/ Margins/ Padding/ Height and Width CSS Introduction: CSS stands for ...

随机推荐

  1. Dell Remote Access Controller 添加和配置 DRAC/MC 用户

    iDRAC设置 单击“Configuration”(配置)选项卡并选择“Users”(用户). 单击“Username”(用户名)列下的 [Available](可用)添加新用户,或单击“Userna ...

  2. 通过 OpenNI 建立 Kinect 3D Point Cloud

    這篇還是算延續前一篇的<透過 OpneNI 合併 Kinect 深度以及彩色影像資料>.在可以透過 OpenNI 讀取到 Kinect 的深度.色彩資訊之後,其實就可以試著用這些資訊,來重 ...

  3. UDP协议疑难杂症全景解析

    转载:http://blog.csdn.net/dog250/article/details/6896949 UDP协议疑难杂症全景解析 2011-10-22 19:26 2989人阅读 评论(4)  ...

  4. map容器对象插入数据的4种方式

    #include <string> #include <iostream>  #include <map>  #include <utility>  u ...

  5. ASP.NET获取上传图片的大小

    1.采用客户端javascript可以取得图片大小 <input id="FileUpload" type="file" size="30&qu ...

  6. linux一部分常用的命令

    如今的web项目,一般在windows下开发,然后部署在linux上.搜索了一下原因,大概是说,linux免费,此外,linux长时间运行都没有问题,可以达到1到2年不停机.因此,需要学习一些常用的l ...

  7. Linux文件权限学习总结

    一.用户对文件或目录都有哪些权限? 四种:读.写.执行.没有权限 二.如何表示这四种权限? 如果用十进制数字表示,分别为:4.2.1.0:如果用字符表示,分别为:r.w.x.-.个人觉得,使用chmo ...

  8. SQLServer:定时作业

    SQLServer:定时作业: 如果在SQL Server 里需要定时或者每隔一段时间执行某个存储过程或3200字符以内的SQL语句时,可以用管理-SQL Server代理-作业来实现 也快可以定时备 ...

  9. NET Core 整合Autofac和Castle

    NET Core 整合Autofac和Castle 阅读目录 前言: 1.ASP.NET Core中的Autofac 2.整合Castle的DynamicProxy 3.注意事项 回到目录 前言: 除 ...

  10. Matlab界面语言切换,自由显示中文或英文语言

    Matlab界面语言切换,自由显示中文或英文语言分享给大家,Matlab是一款商业数学软件,广泛使用于算法的开发.数据发现和数值计算等.不同用户对Matlab显示的语言需求也不一样,一用户习惯使用中文 ...