幻灯片定位问题

时间:2011-01-17 02:50:04

标签: javascript html css

我有一个javascript幻灯片,适用于Windows 7,Firefox,Chrome,IE 8+(我没有资源检查6或7)和Opera。但是我被告知,当使用IE 7的xp时,滑动屏幕会从屏幕右侧抛出。我的问题可能是什么?

这是我的css:

*#page {
 width:940px;
 margin: auto;
 }

#gallery {
 position:relative;
 padding:0px;
 margin:5px 0px;
 width:940px;
 height:320px;
    }

#gallery li { 
 display: block; 
 width:940px; 
 height:320
 list-style:none;
 }*

这是我的javascript:

*var galleryId = 'gallery'; 
var gallery; 
var galleryImages;
var currentImage;
var previousImage;
var preInitTimer;
preInit();

function preInit() {

 if ((document.getElementById)&&(gallery=document.getElementById(galleryId))) {
  gallery.style.visibility = "hidden";
  if (typeof preInitTimer != 'undefined') clearTimeout(preInitTimer); 
 } else {
  preInitTimer = setTimeout("preInit()",2);
 }
}

function fader(imageNumber,opacity) {

 var obj=galleryImages[imageNumber];
 if (obj.style) {
  if (obj.style.MozOpacity!=null) {  

   obj.style.MozOpacity = (opacity/100) - .001;
  } else if (obj.style.opacity!=null) {

   obj.style.opacity = (opacity/100) - .001;
  } else if (obj.style.filter!=null) {

   obj.style.filter = "alpha(opacity="+opacity+")";
  }
 }
}

function fadeInit() {
 if (document.getElementById) {
  preInit(); 
  galleryImages = new Array;
  var node = gallery.firstChild;

  while (node) {
   if (node.nodeType==1) {
    galleryImages.push(node);
   }
   node = node.nextSibling;
  }
  for(i=0;i<galleryImages.length;i++) {

   galleryImages[i].style.position='absolute';
   galleryImages[i].style.top=0;
   galleryImages[i].style.zIndex=0;

   fader(i,0);
  }

  gallery.style.visibility = 'visible';

  currentImage=0;
  previousImage=galleryImages.length-1;
  opacity=100;
  fader(currentImage,100);

  window.setTimeout("crossfade(100)", 1000);
 }
}

function crossfade(opacity) {
  if (opacity < 100) {

   fader(currentImage,opacity);

   opacity += 9;
   window.setTimeout("crossfade("+opacity+")", 50);
  } else {

   fader(previousImage,0);

   previousImage=currentImage;
   currentImage+=1;
   if (currentImage>=galleryImages.length) {

    currentImage=0;
   }

   galleryImages[previousImage].style.zIndex = 0;
   galleryImages[currentImage].style.zIndex = 100;

   opacity=0;
   window.setTimeout("crossfade("+opacity+")", 5000);
  }
}

addEvent(window,'load',fadeInit)

function addEvent(elm, evType, fn, useCapture) 

{
 if (elm.addEventListener){
   elm.addEventListener(evType, fn, useCapture);
   return true;
 } else if (elm.attachEvent){
   var r = elm.attachEvent("on"+evType, fn);
   return r;
 }
} *

和想法?

1 个答案:

答案 0 :(得分:0)

我不知道这实际上是否会做任何事情,或者即使它错了但可能会改变#page到margin:0 auto;而不是margin:auto;