0

ビデオ JS HTML5 プレーヤーを使用していくつかのビデオを再生していますが、ビデオ プレーヤーの下にチャプターの視覚的表現を追加したいと考えています。

私は基本的に、データベースからいくつの章があるかを取得し、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>

そのため、チャプターの実際のサイズになるようにスタイル設定されるチャプター ブレーカー タイトル div と、チャプターを分割するための 1% の太さの単なる線であるチャプター ブレーカーがあります。

次に、JavaScript のオンロード関数を使用して、これらの 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] ?>"; 
    } 

したがって、これは次のようになります。

章の表現

問題は、これが Internet Explorer 以外のすべてのブラウザーで機能することです。
div の幅がまったくスタイル設定されていないかのようです。

したがって、次のようになります。 良くない!

これが機能しない理由を誰かが見たり説明したりできる場合は、非常に役立ちます

.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出力:

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>

div の出力はすべて問題ないように見えますが、javascript はチャプター ブレーカー タイトルの div の幅をスタイル設定していません。

4

1 に答える 1

0

誰かが同様の問題に遭遇した場合に備えて、JavaScript を機能させるために時間遅延を設定する必要がありました。そのため、スクリプトが実行されたときにページが完全にロードされていてはなりません。

于 2013-10-16T11:57:33.010 に答える