描述
特性
原理
使用步骤
<script src="jquery/jquery.min.js">script>
<script src="jquery.stellar.min.js">script>
<div class="content" id="content1">
<p>TEXT HEREp>
div>
<div class="content" id="content2">
<p>TEXT HEREp>
div>
<div class="content" id="content3" data-stellar-background-ratio="0.5">
<p>TEXT HEREp>
div>
<div class="content" id="content4" data-stellar-background-ratio="0.5">
<p>TEXT HEREp>
div>
<div class="content" id="content5" data-stellar-background-ratio="0.5">
<p>TEXT HEREp>
div>
<div class="content" id="content6" data-stellar-background-ratio="0.5">
<p>TEXT HEREp>
div>
.content {
background-attachment: fixed;
height: 400px;
}
#content1 {
background-image: url("..");
}
#content2 {
background-image: url("..");
}
#content3 {
background-image: url("..");
}
#content4 {
background-image: url("..");
}
#content5 {
background-image: url("..");
}
#content6 {
background-image: url("..");
}
$.stellar({
horizontalScrolling: false,
responsive: true
});
参数解释
名称 | 说明 |
---|---|
horizontalScrolling 和 verticalScrolling | 该配置项用来设置视差效果的方向。horizontalScrolling设置水平方向,verticalScro设置垂直方向, 为布尔值,默认为true |
responsive | 该配置项用来制定load或者resize时间触发时是否刷新页面,其值为布尔值,默认为false |
hideDistantElements | 该配置项用来设置移出视线的元素是否隐藏,其值为布尔值,若不想隐藏则设置为false |
data-stellar-ratio=“2” | 定义了此元素针对页面滚动的速度比率,比如,0.5为页面滚动的50%,2为页面滚动的200%,所以数值越大,你可以看到页面元素滚动速度越快。 |
data-stellar-background-ratio | 该配置项用在单个元素中,其值为一个正数,用来改变被设置元素的影响速度。 例如 值为0.3时,则表示背景的滚动速度为正常滚动速度的0.3倍。如果值为小数时最好在样式表中设置 |
具体需求参照示例
<html lang="en">
<head>
<meta charset="UTF-8">
<title>QQTIMtitle>
<link rel="stylesheet" href="css/index.css">
head>
<body>
<nav class="qq_nav">
<div class="wrapper">
<a href="#" class="logo">a>
<ul class="nav">
<li><a class="active" href="#">首页a>li>
<li><a href="#">下载a>li>
<li><a href="#">动态a>li>
ul>
<div class="other">
<ul>
<li><a href="#">qq安全a>li>
<li><a href="#">qq会员a>li>
<li><a href="#">登录a>li>
ul>
<span>当前在线人数:227,763,015span>
div>
<a href="#" class="register">注册a>
div>
nav>
<section class="qq_banner">
<img src="images/banner-logo.png" alt="">
<img src="images/banner-download.png" alt="">
<img src="images/banner-list.png" alt="">
<img src="images/banner-product.png" alt="">
section>
<section class="qq_sound">
<h1>I'm QQ - 每一天,乐在沟通h1>
<div class="bg" data-stellar-background-ratio="0.3">div>
<div class="content">
<div class="iphone">div>
<h2>沟通,是跨越<br>千山万水的亲切声音h2>
<p>无论何时何地,你都能自由享受QQ在各类<br>终端上带来的高清通话,与好友一起想聊多久聊多久p>
div>
section>
<section class="qq_file">
<div class="bg" data-stellar-background-ratio="0.3">div>
<div class="content">
<h2>沟通,是随时随地<br>爽快收发h2>
<p>通过QQ,电脑和手机上的文件都能收发自如,<br>更有手机在线查阅,轻松你的工作和生活。p>
<div class="mac">div>
div>
section>
<section class="qq_interest">
<div class="bg" data-stellar-background-ratio="0.3">div>
<div class="content">
<div class="phone">div>
<h2>沟通,是志同道合<br>的他们放肆青春h2>
<p>即使世界很大,你也不会孤单,在兴趣部落<br>有和你一样的人,期待着和你一起发现精彩。p>
div>
section>
<footer class="qq_footer">
<div class="content">
<div class="plats">
<a class="plmb" href="#" target="_blank">QQ 手机版a>
<a class="plpc" href="#" target="_blank">QQ PC版a>
<a class="plmac" href="#" target="_blank">QQ Mac版a>
<a class="plpad" href="#" target="_blank">QQ Pad版a>
div>
<p>Copyright © 1998- 2017 Tencent. All Rights Reserved.p>
<p>腾讯公司 版权所有p>
div>
footer>
<script src="js/jquery.min.js">script>
<script src="js/jquery.stellar.js">script>
<script src="js/index.js">script>
body>
html>
$(function () {
/*1.引入*/
/*2.结构 data-stellar-background-ratio="0.3" 样式 bg 需要 background-attachment: fixed;*/
/*3.初始化插件*/
$.stellar({
horizontalScrolling: false,
responsive: true
});
});
/*============reset css===========*/
* {
margin: 0;
padding: 0;
}
body {
font-size: 14px;
font-family: "Microsoft YaHei", sans-serif;
color: #333;
}
ul{
list-style: none;
}
a{
color: #333;
text-decoration: none;
}
/*============model css===========*/
.qq_nav{
height: 150px;
background: url("../images/nav_bg.png") repeat-x;
position: absolute;
left: 0;
top: 0;
width: 100%;
}
.qq_nav .wrapper{
width: 1080px;
height: 75px;
margin: 0 auto;
}
.qq_nav .wrapper .logo{
width: 100px;
height: 75px;
background: url("../images/nav_brand.png") no-repeat center;
float: left;
}
.qq_nav .wrapper .nav{
float: left;
}
.qq_nav .wrapper .nav li{
float: left;
font-size: 18px;
line-height: 75px;
margin-left: 20px;
}
.qq_nav .wrapper .nav li a{
display: block;
padding: 0 20px;
}
.qq_nav .wrapper .nav li a.active,
.qq_nav .wrapper .nav li a:hover{
background: #12b7f5;
}
.qq_nav .wrapper .register{
float: right;
height: 36px;
width: 96px;
text-align: center;
line-height: 36px;
font-size: 16px;
background: #12b7f5;
color: #fff;
border-radius: 18px;
margin-top:19px;
}
.qq_nav .wrapper .other{
float: right;
width: 250px;
height: 75px;
}
.qq_nav .wrapper .other ul {
width: 250px;
}
.qq_nav .wrapper .other ul li{
float: right;
margin-left:40px;
}
.qq_nav .wrapper .other ul li a{
font-size: 14px;
text-shadow: 0 0 2px #333;
height: 50px;
line-height: 50px;
}
.qq_nav .wrapper .other span{
float: right;
}
.qq_banner{
height: 880px;
background: url("../images/banner-bg.jpg") no-repeat center top;
padding-top: 150px;
}
.qq_banner img{
display: block;
margin: 20px auto 0;
}
.qq_banner img:last-child{
width: 100%;
/*自适应 等比例缩放 图片有这个特殊效果 */
}
.qq_sound{
}
.qq_sound h1{
height: 300px;
background: url("../images/sound-text.png") no-repeat center/cover;
font-size: 0;
}
.qq_sound .bg{
height: 500px;
background: url("../images/sound-bg.jpg") no-repeat center/cover;
}
.qq_sound .content{
height: 500px;
width: 980px;
margin: 0 auto;
position: relative;
}
.qq_sound .content .iphone{
position: absolute;
left: 0;
top: -200px;
width: 700px;
height: 700px;
background: url("../images/sound-phone.png") no-repeat center top/cover;
}
.qq_sound .content h2{
float: right;
padding-top: 100px;
width: 500px;
text-align: right;
font-size: 40px;
}
.qq_sound .content p{
padding-top: 50px;
float: right;
width: 500px;
text-align: right;
font-size: 18px;
text-shadow: 0 0 2px #333;
}
.qq_file{}
.qq_file .bg{
height: 500px;
background: url("../images/file-bg.jpg") no-repeat center/cover;
}
.qq_file .content{
height: 500px;
width: 980px;
margin: 0 auto;
position: relative;
}
.qq_file .content .mac{
width: 600px;
height: 340px;
background: url("../images/file-mac.png") no-repeat center/cover;
position: absolute;
right: -60px;
top: 100px;
}
.qq_file .content h2{
float: left;
padding-top: 100px;
width: 500px;
text-align: left;
font-size: 40px;
}
.qq_file .content p{
padding-top: 50px;
float: left;
width: 500px;
text-align: left;
font-size: 18px;
text-shadow: 0 0 2px #333;
}
.qq_interest{}
.qq_interest .bg{
height: 500px;
background: url("../images/interest-bg.jpg") no-repeat center/cover;
}
.qq_interest .content{
height: 500px;
width: 980px;
margin: 0 auto;
position: relative;
}
.qq_interest .content .phone{
position: absolute;
left: 0;
top: 0;
width: 350px;
height: 500px;
background: url("../images/interest-phone.png") no-repeat center top/cover;
}
.qq_interest .content h2{
float: right;
padding-top: 100px;
width: 500px;
text-align: right;
font-size: 40px;
}
.qq_interest .content p{
padding-top: 50px;
float: right;
width: 500px;
text-align: right;
font-size: 18px;
text-shadow: 0 0 2px #333;
}
.qq_footer{
height: 250px;
background: #2a2a2a;
font-size: 12px;
text-align: center;
padding-top: 50px;
color: #666;
}
.plats{
width: 800px;
height: 150px;
margin: 0 auto;
display: block;
}
.plats a {
float: left;
background: transparent url(../images/footer.png) no-repeat 10px 0;
text-align: center;
font-size: 12px;
color: #666;
padding-top: 50px;
width: 80px;
margin: 0 60px;
}
.plats a:hover {
color: #12b7f5;
}
.plats a.plmb {
background-position: 0 0;
}
.plats a.plmb:hover {
background-position: 0 -93px;
}
.plats a.plpc {
background-position: -105px 0;
}
.plats a.plpc:hover {
background-position: -105px -93px;
}
.plats a.plmac {
background-position: -210px 0;
}
.plats a.plmac:hover {
background-position: -210px -93px;
}
.plats a.plpad {
background-position: -326px 0;
}
.plats a.plpad:hover {
background-position: -326px -93px;
}
.qq_sound .bg,.qq_file .bg,.qq_interest .bg{
background-attachment: fixed;
}