我正在尝试使用javascript将浮动代码放入Joomla网站。
使用此脚本,代码在Chrome上运行良好:
<script>
window.onscroll = function() {myFunction();};
var towerRightAd = document.getElementById("bodyTowerRightAd");
function myFunction() {
if (document.body.scrollTop > 150) {
if (towerRightAd.className != "bodyTowerRighttAd floatTowerAds" ) {
towerRightAd.className = towerRightAd.className + " floatTowerAds";
}
}
else
{
towerRightAd.className = "bodyTowerRightAd";
}
}
</script>
如何让这段代码适用于FF和IE。
答案 0 :(得分:0)
试试这个:
window.onscroll = function() {
myFunction();
};
var towerRightAd = document.getElementById("bodyTowerRightAd");
function myFunction() {
var scrollTop = window.pageYOffset || document.documentElement.scrollTop;
if (scrollTop > 150) {
if (towerRightAd.className != "bodyTowerRighttAd floatTowerAds" ) {
towerRightAd.className = towerRightAd.className + " floatTowerAds";
}
} else {
towerRightAd.className = "bodyTowerRightAd";
}
}