Web前端学习笔记——HTML5与CSS3之QQ TIM案例

《QQ TIM》案例

Stellar插件
  • 描述

    • 视差滚动(Parallax Scrolling)指网页滚动过程中,
      多层次的元素进行不同程度的移动,视觉上形成立体运动效果的网页展示技术
      主要核心就是前景和背景以不同的速度移动,从而创造出3D效果。
      这种效果可以给网站一个很好的补充。
  • 特性

    • 视差滚动效果酷炫,适合于个性展示的场合。
    • 视差滚动徐徐展开,适合于娓娓道来,讲故事的场合。
    • 视差滚动容易迷航,需要具备较强的导航功能。
  • 原理

    • 传统的网页的文字、图片、背景都是一起按照相同方向相同速度滚动的,
      而视差滚动则是在滚动的时候,内容和多层次的背景实现或不同速度,或不同方向的运动。
      有的时候也可以加上一些透明度、大小的动画来优化显示。利用background-attachment属性实现。
  • 使用步骤

    • 引用文件
        <script src="jquery/jquery.min.js"></script>
        <script src="jquery.stellar.min.js"></script>
    
    • html结构
        <div class="content" id="content1">
            <p>TEXT HERE</p>
        </div>
        <div class="content" id="content2">
            <p>TEXT HERE</p>
        </div>
        <div class="content" id="content3" data-stellar-background-ratio="0.5">
            <p>TEXT HERE</p>
        </div>
        <div class="content" id="content4" data-stellar-background-ratio="0.5">
            <p>TEXT HERE</p>
        </div>
        <div class="content" id="content5" data-stellar-background-ratio="0.5">
            <p>TEXT HERE</p>
        </div>
        <div class="content" id="content6" data-stellar-background-ratio="0.5">
            <p>TEXT HERE</p>
        </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("..");
        }
    
    • js初始化
        $.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倍。如果值为小数时最好在样式表中设置
完成视觉滚动差页面开发
  • 模块一: 导航(nav)
  • 模块二: 宣传(banner)
  • 模块三: 语音聊天(sound)
  • 模块四: 文件传输(file)
  • 模块五: 兴趣部落(interest)
  • 模块六: 底部(footer)

具体需求参照示例

  • index.html
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>QQTIM</title>
    <link rel="stylesheet" href="css/index.css">
    <!--[if lte IE 8]>
    <script src="js/html5shiv.min.js"></script>
    <![endif]-->
</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,015</span>
        </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">
    <!--seo优化-->
    <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>
  • index.js
$(function () {
    /*1.引入*/
    /*2.结构   data-stellar-background-ratio="0.3"  样式 bg 需要 background-attachment: fixed;*/
    /*3.初始化插件*/
    $.stellar({
        horizontalScrolling: false,
        responsive: true
    });
});
  • index.css
/*============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;
}

发布了296 篇原创文章 · 获赞 562 · 访问量 50万+

猜你喜欢

转载自blog.csdn.net/tichimi3375/article/details/82837516