繁体   English   中英

使用javascript旋转文本-在IE8中不起作用

[英]rotating text using javascript - not working in IE8

我正在使用Bootstrap构建,并具有一个标题区域,该区域在左侧旋转文本,并利用Bootstrap的轮播在右侧旋转图像。 文本仅是复制的几个单词,主要的单词较大且具有脚本性,下面的单词具有不同的类型。 我使用的javascript会按原样旋转第一个大字,但将其他字堆叠在一起。 在大多数浏览器中,一切都可以正常运行,但是IE8给了我这个问题。

谁能看看我的代码,并给我任何帮助来解决此问题?

这是我的html:

<div class="rotator">
   <ul>
      <li class="show">

         <p class="script">Discover<br/><br/>
         <span class="captionwhite">the many uses<br/>of glass block</span></p>
      </li>

      <li class="show">

         <p class="script">Create<br/><br/>
         <span class="captionwhite">a beautiful<br/>shower enclosure</span></p>
      </li>

      <li class="show">

          <p class="script">Illuminate<br/><br/>
          <span class="captionwhite"> your bathroom<br/>naturally</span></p>
       </li>
     </ul>
   </div>

这是我的CSS:

/* rotator in-page placement */
    div.rotator {       
    position:relative;

}
/* rotator css */
    div.rotator ul li {
    position:absolute;
    list-style: none;
}

这是javascript:

function theRotator() {
    //Set the opacity of all images to 0
    $('div.rotator ul li').css({opacity: 0.0});

    //Get the first image and display it (gets set to full opacity)
    $('div.rotator ul li:first').css({opacity: 1.0});

    //Call the rotator function to run the slideshow, 3000 = change to next image after 3 seconds

    setInterval('rotate()',3000);

}

function rotate() { 
    //Get the first image
    var current = ($('div.rotator ul li.show')?  $('div.rotator ul li.show') : $('div.rotator ul li:first'));

    if ( current.length == 0 ) current = $('div.rotator ul li:first');

    //Get next image, when it reaches the end, rotate it back to the first image
    var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('div.rotator ul li:first') :current.next()) : $('div.rotator ul li:first'));

    //Un-comment the 3 lines below to get the images in random order

    //var sibs = current.siblings();
    //var rndNum = Math.floor(Math.random() * sibs.length );
    //var next = $( sibs[ rndNum ] );


    //Set the fade in effect for the next image, the show class has higher z-index
    next.css({opacity: 0.0})
    .addClass('show')
    .animate({opacity: 1.0}, 3000);

    //Hide the current image
    current.animate({opacity: 0.0}, 3000)
    .removeClass('show');

};



$(document).ready(function() {      
    //Load the slideshow
    theRotator();
    $('div.rotator').fadeIn(3000);
    $('div.rotator ul li').fadeIn(3000); // tweek for IE
});

任何帮助,将不胜感激!

根据我的评论:

IE8不支持 CSS 不透明规则。 为此,您必须使用专有的Microsoft过滤规则 (仅在IE浏览器中有效)。 或者,更容易使用jQuery的.hide()或设置CSS规则显示:none;。

在看了一些代码之后,最好的选择可能是使用一些jQuery的内置函数。 您需要根据对opacity设置的操作,使用几个jQuery选项之一替换大多数opacity用法(通过使用.css().animate() )。

对于.css({opacity: 0.0}) (立即隐藏事物),您应该改用.hide()

myElement.hide();

对于.css({opacity: 1.0}) (立即显示内容),您应该改用.show()

myElement.show();

对于使用opacity (缓慢显示或隐藏)对.animate()调用,您应该改用.fadeIn().fadeOut() 您似乎已经在JS代码底部的IE调整中使用了.fadeIn() 您可以在具有.animate({opacity: 1.0}, 3000)以相同的方式使用它,而只需使用.fadeIn(3000) .fadeOut(3000)代替.animate({opacity: 0.0}, 3000) 如果您没有显式传递持续时间的数字,则.fadeIn() .fadeOut().animate()的默认持续时间都相同,均为400

jQuery函数链接指向jQuery API文档,您可以在这些页面中找到完整的用法文档以及示例。

如果您在IE8中使用.fadeIn().fadeOut() 遇到问题 ,则此问题可能会有所帮助。

暂无
暂无

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

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