zoukankan      html  css  js  c++  java
  • javaScript之BOM操作1

    <!doctype html>
    <html lang="en">
     <head>
      <meta charset="UTF-8">
      <title>Document</title>
      <style>
        #div1 {100px; height:100px; background:red; position: absolute; right:0;}
      </style>
      <script>
    	window.onresize = window.onload = window.onscroll = function() {
    		var oDiv = document.getElementById("div1");
    		var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
    		var t = (document.documentElement.clientHeight - oDiv.offsetHeight)/2; 
    		oDiv.style.top = scrollTop + t + "px";
    	}
      </script>
     </head>
     <body style="height:2000px;">
      <div id="div1"></div>
     </body>
    </html>
    

      这种方法可以将div块实时显示到可视区中间,但是会出现闪烁问题。解决办法1:

    <!doctype html>
    <html lang="en">
     <head>
      <meta charset="UTF-8">
      <title>Document</title>
      <style>
        #div1 {100px; height:100px; background:red; position: fixed; right:0; top:50%; margin-top:-50px;}
      </style>
     </head>
     <body style="height:2000px;">
      <div id="div1"></div>
     </body>
    </html>
    

      通过css布局解决闪烁问题,但是IE6并不支持fixed。可以使用动画滑入的方式解决IE6的固定定位问题,暂时不录入本文中。

  • 相关阅读:
    在linux下Ant的环境配置
    在linux下Java的环境配置
    CSS列表逆序
    HTML元素基础学习
    第一天---HTML基础学习
    排球计分程序
    罗辑思维:怎样成为一个高手 观后感
    十八周个人作业
    本周个人作业
    个人作业
  • 原文地址:https://www.cnblogs.com/tzzt01/p/6256059.html
Copyright © 2011-2022 走看看