I am creating a slight minor parallax effect with this code.Everything works fine everywhere,except IE.I am using IE 9.
Jsfiddle-javascript
Jsfiddle-jquery
<div id="head"> i </div>
<div id="subHead"> can </div>
<div id="content"> haz </div>
Javascript
window.onscroll = function(ev){
var subHead = document.getElementById('subHead'),
topHeight = document.getElementById('head').offsetHeight;
subHead.style.top = (topHeight - document.body.scrollTop / 4) + 'px';
};
CSS
#head, #subHead{
position: fixed;
height: 80px;
width: 100%;
display: block;
background: #c00;
left: 0;
top: 0;
z-index: 10;
}
#subHead{
z-index: 4;
background: #cd0;
top: 80px;
}
#content{
position: relative;
z-index: 6;
height: 1000px;
background: #eee;
margin-top: 160px;
}
i tried googling some cross browser tricks,but in vain...Is there any way to make it work in IE ?thanks a lot.
Edit:
Purpose: To make a 1 div move slower than another when a user scrolls.
Logic:make the div fixed via css and change its postion via javascript http://jsfiddle.net/MRbWY/11/
Error in IE.The javascript doesnt work.hence the div remains only fixed
Scroll down the Internet zone section until you locate the “Scripting” header. Look for “Active Scripting” and select “Enable” on all options to unblock JavaScript. Now, save your settings by clicking OK on each of the next two screens (Security and Internet Options). Restart your Internet Explorer.
Internet Explorer 11 doesn't support JavaScript versions later than ES5. If you want to use the syntax and features of ECMAScript 2015 or later, or TypeScript, you have two options as described in this article. You can also combine these two techniques.
All the modern browsers come with built-in support for JavaScript. Frequently, you may need to enable or disable this support manually. This chapter explains the procedure of enabling and disabling JavaScript support in your browsers: Internet Explorer, Firefox, chrome, and Opera.
Show activity on this post. JavaScript classes and constructor not support IE browser, so, in the IE browser, it will show the "SCRIPT1002: Syntax error" error. Show activity on this post. The JS parser has to parse the JavaScript you tell it to load, even if it is a function that never executes.
document.body.scrollTop was always reading zero, a bit of digging turns up this question, you want to use document.documentElement.scrollTop
for IE.
updated your fiddle
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With