zoukankan      html  css  js  c++  java
  • 无聊找到一个效果,滚动网页模块被压扁的感觉

      当鼠标滚动的时候,背景图设置为固定定位,那么效果就是感觉模块被压扁的感觉,再稍微用js更改背景图y轴的定位来增加效果,

    background-attachment 以前没用过,这次用到了。
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    <style>
    .box { display:-webkit-box; width:700px;}
    .box .item2{ -webkit-box-flex:2; background-color:#fddfdd;}
    .box .item3{ -webkit-box-flex:2; background-color:#C63;}
    .box .item:first-child { width:200px;}
    header { height:700px; background-image:url(01.jpg);
    background-size: cover;
    
    background-repeat: no-repeat;
    background-attachment: fixed;}
    nav { height:900px;}
    </style>
    </head>
    
    <body>
    <div class="ds">
      <header></header>
      <nav>导航</nav>
      <aside>侧边栏</aside>
      <article>文章</article>
      <footer>页尾</footer>
    </div>
    
    <script>
    window.onscroll = function (){
        
         if(document.body.scrollTop>0 || document.documentElement.scrollTop>0){
             
             var top = document.body.scrollTop ;
             if(top<=700){
             var headr = document.getElementsByTagName("header")[0];
             headr.style.backgroundPosition = "0px " + -top/8+"px";
             }
             }
        
        }
    
    
    </script>
    </body>
    </html>
  • 相关阅读:
    QTP自动化测试进阶
    疯狂Java实战演义
    软件开发之韵:和谐敏捷
    Android应用开发详解
    操作系统直接决定了计算机系统的整体性能
    iBATIS框架源码剖析
    PHP 5完全攻略
    天气地图系统
    OpenSolaris系统管理
    Asp.net MVC 3实例学习之ExtShop(三)——完成首页
  • 原文地址:https://www.cnblogs.com/xiaotian747/p/3755514.html
Copyright © 2011-2022 走看看