简体   繁体   English

为什么JavaScript样式可用于Internet Explorer以外的所有浏览器?

[英]Why is JavaScript styling working with all browsers except Internet Explorer?

I'm using video JS HTML5 player to play some videos and I want to add a visual representation of the chapters underneath the video player. 我正在使用视频JS HTML5播放器播放一些视频,并且想在视频播放器下方添加章节的直观表示。

I'm basically grabbing how many chapters there are from the database and create that number of the divs with PHP. 我基本上是从数据库中获取多少章,并使用PHP创建该数量的div。

 <div class="chapter-progress">
        <div class="chapter-breaker"></div>
        <? $tableName = 'sourceChapters';      
        $mysqlQuery = "SELECT * FROM " . $tableName . " WHERE recSourceId = "                          
       .$sourceVideo['recId']. " ORDER BY recOrdering ASC;";
        $sourceChapters = mysql_query($mysqlQuery); ?>
       <? $chapterBreakerNo = 0; ?>
       <? while($chapterBreakers = mysql_fetch_array($sourceChapters)){ ?>
          <div class="chapter-breaker-title" id="chapter-breaker-title<?=$chapterBreakerNo?>">    
          <p><?=$sourceChapters['recContent']?></p></div>
          <div class="chapter-breaker" id="chapter-breaker<?=$chapterBreakerNo?>"></div>
          <? $chapterBreakerNo++ ?>
          <? } ?>
          <div class="chapter-breaker-title" id="last-title"></div>
          <div class="chapter-breaker" style="float:right"</div>
  </div>

So there is chapter-breaker-title divs that are going to be styled to be the actual size of the chapters and there are chapter breaker which are just a line, 1% thick to split the chapters. 因此,有一些章断开器标题div的样式将设置为各章的实际大小,并且有章断开器只是一条线,粗细为1%,用于拆分各章。

I then use a JavaScript onload function to style these divs. 然后,我使用JavaScript onload函数为这些div设置样式。

 /* -----------------------------------------------function for styling the chapter progress bar ---------------------------------------*/

    function styleChapters(){
        //also run the chapter system on load
        chapterSys();
        // total video duration 
        var duration = myPlayer.duration();
        //find the time difference for the first chapter , this is just the chapter time 
        var timeDif = (<?=$chapterPlayOffsets[0]?>);
        // work out the percentage width for the div width
        var percentageMargin = ((timeDif/duration) * 100 -1);
        //get the first chapter breaker title and style the width 
        document.getElementById("chapter-breaker-title0").style.width = percentageMargin + "%";
        document.getElementById("chapter-breaker-title0").innerHTML="00";
       // for the rest of the chapters

       <? for($i=1;$i<count($chapterPlayOffsets);$i++) { ?>
        //total video duration
        var duration = myPlayer.duration();
        // find the difference between the chapter and the previous chapter
        var timeDif = (<?=$chapterPlayOffsets[$i]?>) - (<?=$chapterPlayOffsets[$i-1]?>);
        // get the percentage for div length minus 1% for the width of the chapter breakers
        var percentageMargin = ((timeDif/duration) * 100) -1;
        //style each of the divs width
        document.getElementById("chapter-breaker-title<?=$i?>").style.width = percentageMargin + "%";
                    //put the chapter title in 
        document.getElementById("chapter-breaker-title<?=$i?>").innerHTML="<?= $chapterTitles[$i-1] ?>";

      <? } ?>
      //put the last title in 
      <? $lastTitle = count($chapterPlayOffsets)-1 ?>
      document.getElementById("last-title").innerHTML="<?=$chapterTitles[$lastTitle] ?>"; 
    } 

So this is what it should look like: 因此,它应该是这样的:

各章的表示

The problem is that this works on all browsers apart from Internet Explorer. 问题是,这适用于Internet Explorer以外的所有浏览器。
It's as if the divs are not having their width styled at all. 好像div根本没有设置其宽度样式。

So it looks like this: 所以看起来像这样: 不好!

If anyone can see or explain why this may not be working, it would be very helpful 如果任何人都能看到或解释为什么这可能行不通,那将非常有帮助

.chapter-progress{
width:100%;
height:20px;
background: rgb(255,204,0)
  url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAYAAAAGCAYAAADgzO9IAAAAP0lEQVQIHWWMAQoAIAgDR/QJ/Ub//04+w7ZICBwcOg5FZi5iBB82AGzixEglJrd4TVK5XUJpskSTEvpdFzX9AB2pGziSQcvAAAAAAElFTkSuQmCC)
-50% 0 repeat; 
margin:auto;
float:left; 
}

.chapter-breaker{
height:100%;
width:1%;
background-color: rgb(0, 51, 153);
    float:left;
}

.chapter-breaker-title{
    height:100%;
    float:left;
}

HTML output : HTML输出:

div class="chapter-progress">
<div class="chapter-breaker"></div>
<div class="chapter-breaker-title" id="chapter-breaker-title0">
    00
</div>
<div class="chapter-breaker" id="chapter-breaker0"></div>
<div class="chapter-breaker-title" id="chapter-breaker-title1">
    01
</div>
<div class="chapter-breaker" id="chapter-breaker1"></div>
<div class="chapter-breaker-title" id="chapter-breaker-title2">
    02
</div>
<div class="chapter-breaker" id="chapter-breaker2"></div>
<div class="chapter-breaker-title" id="chapter-breaker-title3">
    03
</div>
<div class="chapter-breaker" id="chapter-breaker3"></div>
<div class="chapter-breaker-title" id="chapter-breaker-title4">
    04
</div>
<div class="chapter-breaker" id="chapter-breaker4"></div>
<div class="chapter-breaker-title" id="last-title">
    05
</div>
<div class="chapter-breaker" style="float: right;">
</div>
</div>

The ouput of the divs all seem fine to me but the javascript has not styled the width of the chapter-breaker-title divs 的div的输出对我来说似乎都不错,但是javascript尚未设置Chapter-breaker-title div的宽度

以防万一有人遇到类似的问题,我不得不在我的JavaScript上放置时间延迟才能使其正常工作,因此在触发脚本时,必须在页面未完全加载之前。

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

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