search
HomeWeb Front-endHTML TutorialLet IE6 support the position:fixed method, CSS expression and JavaScript eval explained_html/css_WEB-ITnose

When making ceiling effects or fixed effects, it is most convenient to use position:fixed, but the evil IE6 does not have the attribute value fixed, and we want to make IE6 behave like fixed Fixing it at a certain position in the browser and using onscroll to change the top value is one method, but if the wheel scrolls too fast, flickering will occur. If an advanced browser also uses it this way, it would obviously be inelegant, unless the browser version is determined in JS. But what I want to explain here is the use of CSS to achieve the fixed effect.
Thousands of words are not as good as one example:

The above is the author’s fix for testing IE6 under IETester. Pay attention to the scroll bar. The navigation uses position:fixed.
The core code is as follows:

1 .nav {    /* nav为导航栏 */2     position:fixed;3     _position: absolute;4     top:0;5     _top:expression(eval(documentElement.scrollTop));6     background: #FAA;7 }

Using hack technology, the attributes represented by the underline are only recognized by IE6 and below. (Because only IE6 and below do not support fixed, so special processing)
The above effect can achieve the fixed effect under IE6. It is not easy to understand _top:expression(eval(documentElement.scrollTop)); you need to understand the meaning and usage of expression and eval, which is what will be explained below.

Expression is a unique attribute of IE. It supports IE5 and above and is used to write JavaScript code in CSS. That is to say, the brackets of expression can be a piece of JavaScript code.

eval means executing a statement or expression of the string content and returning its result.


Usage: eval(codes);

Parameters:

  • codes -- expression or statement in string form
  • Return value:

  • If there are no parameters, return undefined
  • If there is a return value, this value will be returned, otherwise undefined
  • If it is an expression, return the value of the expression
  • If the value of the statement is returned for a statement
  • If the value of the last statement is returned for multiple statements or expressions

  • After understanding expression and eval, _top:expression(eval( documentElement.scrollTop)); is not difficult to understand. documentElement.scrollTop obtains the position of the scroll bar under IE, and the top value is equivalent to the position of the scroll bar from the top. If the scrollTop value changes, _top changes accordingly.
    And why use eval? Because documentElement.scrollTop is actually a statement and has no return value, which is equivalent to executing a=1 in JS without performing any operations. If we want to get the documentElement.scrollTop value, we need to return it, and we only need to use eval.
    In this way, all browsers can have a fixed effect, but you will find that flickering will still occur when scrolling the mouse wheel under IE6. This is because when the scroll bar scrolls or the browser size changes, IE6 The weird rendering engine resets everything and redraws the page, so you get vibration or flickering issues. Using backgroune-attachment:fixed; added to html or body will force the CSS to be loaded before the page is redrawn, because the CSS processed before redrawing, that is, your expression has been changed before redrawing, unlike the previous redrawing. Change only after painting. This way there will be no flickering when your mouse scrolls. This completely achieves the fixed effect. The code is as follows:
    body { _background: url(about: blank) fixed}

    Summary:
    fixed cannot be implemented under IE6, so absolute is used to simulate fixed, so JS needs to be used. For processing only for IE6, JavaScript can be written in CSS through IE's unique expresstion, thereby changing the top value in real time to simulate a fixed effect. However, IE6 reloads CSS when scrolling or resizing the browser, so use background-attachment:fixed in the body to load CSS before re-rendering the page.

    Code:

     1 body {_background: url(about:blank) fixed} 2  3 .nav { 4  5     position: fixed; 6  7     _position: absolute; 8  9     top: 0;10 11     _top: expression(eval(documentElement.scrollTop));    12 13     // top值为想要固定定位的位置,设置left同理,设置right与bottom需要通过scrollLeft及scrollTop进行计算,如下注释14 15     // 固定左:_left:expression(eval(documentElement.scrollLeft));16 17     // 固定右:_left:expression(eval(documentElement.scrollLeft + documentElement.clientWidth - this.offsetWidth));18 19     // 固定下:_top:expression(eval(documentElement.scrollTop + documentElement.clientHeight - this.offsetHeight));20 21 }

    The above is the perfect solution to the fixed method under IE6. If you have any questions or concerns please leave a message.

    Statement
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
    演示win7调整屏幕亮度的方法演示win7调整屏幕亮度的方法Jul 08, 2023 pm 07:49 PM

    不同的电脑系统在调整屏幕亮度的操作方法上会有些不同,最近就有使用win7系统的网友不知道win7怎么调整屏幕亮度,看久了电脑眼睛比较酸痛。下面小编就教下大家win7调整屏幕亮度的方法。具体的操作步骤如下:1、点击win7电脑左下角的“开始”,在弹出的开始菜单中选择“控制面板”打开。2、在打开的控制面板中找到“电源选项”打开。3、也可以用鼠标右键电脑右下角的电源图标,在弹出的菜单中,点击“调整屏幕亮度”,如下图所示。两种方法都可以用。4、在打开的电源选项窗口的最下面可以看到屏幕亮度调整的滚动条,直

    win10监控摄像头打开照片的方法win10监控摄像头打开照片的方法Jul 10, 2023 pm 09:41 PM

    如果我们手头没有手机,只有电脑,但我们必须拍照,我们可以使用电脑内置的监控摄像头拍照,那么如何打开win10监控摄像头,事实上,我们只需要下载一个相机应用程序。打开win10监控摄像头的具体方法。win10监控摄像头打开照片的方法:1.首先,盘快捷键Win+i打开设置。2.打开后,进入个人隐私设置。3.然后在相机手机权限下打开访问限制。4.打开后,您只需打开相机应用软件。(如果没有,可以去微软店下载一个)5.打开后,如果计算机内置监控摄像头或组装了外部监控摄像头,则可以拍照。(因为人们没有安装摄

    基于Java的机器视觉实践和方法介绍基于Java的机器视觉实践和方法介绍Jun 18, 2023 am 11:21 AM

    随着科技的不断发展,机器视觉技术在各个领域得到了广泛应用,如工业自动化、医疗诊断、安防监控等。Java作为一种流行的编程语言,其在机器视觉领域也有着重要的应用。本文将介绍基于Java的机器视觉实践和相关方法。一、Java在机器视觉中的应用Java作为一种跨平台的编程语言,具有跨操作系统、易于维护、高度可扩展等优点,对于机器视觉的应用具有一定的优越性。Java

    win7怎么调屏幕亮度的两种简单方法win7怎么调屏幕亮度的两种简单方法Jul 08, 2023 pm 06:33 PM

    目前有很多屏幕亮度调整软件,我们可以通过使用软件进行快速调整或者通过显示器上自带的亮度功能进行调整。以下是详细的Win7屏幕亮度调整方式,您可以通过教程中的方法进行快速调整即可。Win7系统电脑怎么调节屏幕亮度教程:1、依次点击“计算机—右键—控制面板”,如果没有也可以在搜索框中进行搜索。2、点击控制面板下的“硬件和声音”,或者点击“外观和个性化”都可以。3、点击“NVIDIA控制面板”,有些显卡可能是AMD或者Intel的,请根据实际情况选择。4、调节图示中亮度滑块即可。5、还有一种方法,就是

    Go 语言中的方法是怎样定义和使用的?Go 语言中的方法是怎样定义和使用的?Jun 10, 2023 am 08:16 AM

    Go语言是近年来备受青睐的编程语言,因其简洁、高效、并发等特点而备受开发者喜爱。其中,方法(Method)也是Go语言中非常重要的概念。接下来,本文就将详细介绍Go语言中方法的定义和使用。一、方法的定义Go语言中的方法是带有接收器(Receiver)的函数,它是一个与某个类型绑定的函数。接收器可以是值类型或者指针类型。用于接收者的参数可以在方法名

    图文详解如何下载win10系统方法图文详解如何下载win10系统方法Jul 16, 2023 pm 01:25 PM

    如今微软的Windows系统已经更新换代到了Windows10版本。很多以前还在使用Windows7系统的用户都想体验这个新版本Windows10系统。下面小编就来说说如何下载win10系统下载的方法,大家快来看看。1、首先下载一个小白重装系统软件,然后点击在线重装,下载win10系统。2、然后就开始系统镜像的下载了。3、系统镜像下载完成就是环境部署了。然后win10系统就下载完成啦。4、重启之后开始安装系统,安装完成就能进入桌面咯。以上就是如何下载win10系统的方法介绍啦,希望能帮助到大家。

    PHP文件下载方法及常见问题解答PHP文件下载方法及常见问题解答Jun 09, 2023 pm 12:37 PM

    PHP是一个广泛使用的服务器端编程语言,它的许多功能和特性可以将其用于各种任务,包括文件下载。在本文中,我们将了解如何使用PHP创建文件下载脚本,并解决文件下载过程中可能出现的常见问题。一、文件下载方法要在PHP中下载文件,我们需要创建一个PHP脚本。让我们看一下如何实现这一点。创建下载文件的链接通过HTML或PHP在页面上创建一个链接,让用户能够下载文件。

    使用PHP数组实现数据缓存和存储的方法和技巧使用PHP数组实现数据缓存和存储的方法和技巧Jul 16, 2023 pm 02:33 PM

    使用PHP数组实现数据缓存和存储的方法和技巧随着互联网的发展和数据量的急剧增长,数据缓存和存储成为了我们在开发过程中必须要考虑的问题之一。PHP作为一门广泛应用的编程语言,也提供了丰富的方法和技巧来实现数据缓存和存储。其中,使用PHP数组进行数据缓存和存储是一种简单而高效的方法。一、数据缓存数据缓存的目的是为了减少对数据库或其他外部数据源的访问次数,从而提高

    See all articles

    Hot AI Tools

    Undresser.AI Undress

    Undresser.AI Undress

    AI-powered app for creating realistic nude photos

    AI Clothes Remover

    AI Clothes Remover

    Online AI tool for removing clothes from photos.

    Undress AI Tool

    Undress AI Tool

    Undress images for free

    Clothoff.io

    Clothoff.io

    AI clothes remover

    AI Hentai Generator

    AI Hentai Generator

    Generate AI Hentai for free.

    Hot Article

    R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
    2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
    Repo: How To Revive Teammates
    4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
    Hello Kitty Island Adventure: How To Get Giant Seeds
    4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

    Hot Tools

    MantisBT

    MantisBT

    Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

    PhpStorm Mac version

    PhpStorm Mac version

    The latest (2018.2.1) professional PHP integrated development tool

    VSCode Windows 64-bit Download

    VSCode Windows 64-bit Download

    A free and powerful IDE editor launched by Microsoft

    Notepad++7.3.1

    Notepad++7.3.1

    Easy-to-use and free code editor

    Atom editor mac version download

    Atom editor mac version download

    The most popular open source editor