简体   繁体   English

Javascript适用于doctype html4,但不适用于html5

[英]Javascript works with doctype html4 but not html5

I've attempted to run several of the "falling snow background" type scripts available at scriptmania. 我尝试运行scriptmania上提供的几种“落雪背景”类型脚本。 Just javascript, no jquery. 只是javascript,没有jquery。

I'm puzzled by the fact that some of them work fine in IE, but fail to animate in FF, Chrome or Safari when the doctype is set to HTML5. 我感到困惑的是,其中一些在IE中可以正常工作,但是当doctype设置为HTML5时却无法在FF,Chrome或Safari中制作动画。 The scripts do run in any of the above browsers when the doctype is set to HTML 4.0 Transitional. 当doctype设置为HTML 4.0 Transitional时,脚本会在上述任何浏览器中运行。

Here are links to a couple of scripts that have this behavior: 以下是具有这种行为的几个脚本的链接:

http://rainbow.arch.scriptmania.com/scripts/bg/snow_fall.html http://rainbow.arch.scriptmania.com/scripts/bg/snow_fall.html

http://rainbow.arch.scriptmania.com/scripts/bg/autumn_fall_timeout.html http://rainbow.arch.scriptmania.com/scripts/bg/autumn_fall_timeout.html

Any pointers as to what might be the root cause of the failures and/or fixes would be appreciated. 任何有关可能是故障和/或修复的根本原因的指针将不胜感激。

The HTML 4.01 Transitional Doctype with no URL component triggers Quirks mode in browsers. 没有URL组件的HTML 4.01 Transitional Doctype会在浏览器中触发Quirks模式。

The HTML 5 Doctype triggers standards mode in browsers. HTML 5 Doctype在浏览器中触发标准模式。

In Quirks mode, numerous bugs of older browsers (from the 1990s) are emulated. 在Quirks模式下,模拟了旧浏览器(从1990年代开始)的许多错误。

Dependancy on any of these bugs could be the cause of the problem, but the most likely is that something is setting a CSS property which expects a length but giving it a Number . 依赖于这些错误中的任何一个都可能是导致问题的原因,但是最有可能的原因是某些东西正在设置CSS属性,该属性期望一个长度,但是给它一个Number Lengths other than 0 require units (such as 23px ). 0长度要求单位(例如23px )。

Web Oficial: 网络官方:

http://rainbow.arch.scriptmania.com/scripts/bg/snow_fall_2.html http://rainbow.arch.scriptmania.com/scripts/bg/snow_fall_2.html

Download: 下载:

http://rainbow.arch.scriptmania.com/scripts/bg/snowstorm.js http://rainbow.arch.scriptmania.com/scripts/bg/snowstorm.js

Code: 码:

<!-- SNOW TAGS START -->

<!-- Copy the <script> tag into your own page(s) for the snow effect. That is all! (No CSS etc. is needed) -->
<script type="text/javascript" src="snowstorm.js"></script>
<!-- now, we'll customize the snowStorm object -->
<script type="text/javascript">
snowStorm.flakesMaxActive = 95; // show more snow on screen at once
snowStorm.snowStick = true; // When false, snow will never sit at the bottom
snowStorm.animationInterval = 33; // 20 = fast + smooth, but 50 = more but slower
</script>

<!-- SNOW TAGS END -->

Open your file snowstorm.js is go line 41 打开文件snowstorm.js,进入第41行

before: 之前:

this.zIndex = 0; this.zIndex = 0; // CSS stacking order applied to each snowflake // CSS堆叠顺序应用于每个雪花

after: 后:

this.zIndex = 1000; this.zIndex = 1000; // CSS stacking order applied to each snowflake // CSS堆叠顺序应用于每个雪花

Problem body layer is can not see the snow to mean 0 is none, so the need to change for 1000 is available see the front of the body shows snow in front. 问题的身体层是看不到雪,意味着0为零,因此需要更改为1000才可用,请参见身体前面显示雪在前面。


sry bad english 对不起英语

Merry Christmas 2014 and New years 2015 ;-) 2014年圣诞节快乐,2015年新年快乐;-)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM