设置为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. Java的云打印Lodop

        打印某一个网页上的内容我们都经常遇到过,比如网上申请港澳通行证时需要填写申请表,然后把申请表给打印出来.像这样的打印技术是怎么实现?这种打印可以通过一种叫云打印的插件来做,按我的理解云打印的技 ...

  2. POJ 3254 Corn Fields(DP + 状态压缩)

    题目链接:http://poj.org/problem?id=3254 题目大意:Farmer John 放牧cow,有些草地上的草是不能吃的,用0表示,然后规定两头牛不能相邻放牧.问你有多少种放牧方 ...

  3. Ubuntu系统的安装

    在上一篇博客中,我们已经建立了一个“空白”的虚拟Ubuntu镜像,在这篇博客中,我们将介绍如何安装并进入完整的Ubuntu系统. 写在前面:不同版本的系统在安装过程中,有些操作可能会不同,但是其核心步 ...

  4. 【技术·水】浅谈Dism++清理插件开发

    前言 昨天我发布了NCleaner,一款Dism++清理插件(地址:http://bbs.pcbeta.com/viewthread-1692182-1-1.html) 有些人想要我开源NCleane ...

  5. 第16章 网络IPC:套接字总结

    1 套接字是通信端点的抽象 创建套接字: int socket(int domain,int type,int protocol) domain:通信域 AF_INET.AF_INET6.AF_LOC ...

  6. [翻译][MVC 5 + EF 6] 1:创建数据模型

    原文:Getting Started with Entity Framework 6 Code First using MVC 5 1.新建MVC项目: 2.修改Views\Shared\_Layou ...

  7. HTML 多媒体

    1.多媒体简介 Web 上的多媒体指的是音效.音乐.视频和动画,多媒体有多种不同的格式,它可以是听到或看到的任何内容,文字.图片.音乐.音效.录音.电影.动画等等.在互联网上,几乎在所有网站都能发现嵌 ...

  8. NotePad++更改背景颜色

    白色的编辑框看得眼睛不舒服,怎么样更改NotePad++的背景颜色使眼睛更舒服些? 1.设置--语言格式设置 2.设置背景色 “背景色”一栏,选择背景色颜色   “使用全局背景色”一栏要打上√,否则无 ...

  9. C#中通过调用Dll函数时,执行一段时间后,就会报内存可能被破坏的错的解决办法

    遇到同样的问题,已经解决的:http://blog.csdn.net/youxiazzz12/article/details/24313347

  10. 国内外免费PHP开源建站程序一览(最全)

    论坛社区:Discuz.PHPWind.ThinkSAAS.phpBB CMS内容管理:DedeCMS.PHPCMS.帝国CMS.齐博CMS.Drupal 企业建站:CmsEasy.KingCMS.P ...