knockout.js - MediaElement JS is not styling my audio tag if it is inside the for each loop in Knockout JS -


hi using knockout js , mediaelement js together.

mediaelement js plugin style/customize audio player (html5).

here's audio snippet inside foreach loop:

<tbody data-bind="foreach: tracks">     <tr class="search-track" data-bind="attr: { id: 'search-track-' + $index() + '' }">        <td class="search-title-col" data-bind="attr: { id: 'search-col-' + $index() + '' }">           <div class="audio-player">         <h2>the lawdz - evidence song</h2>         <audio id="audio-player" src="media/evidence-song.mp3" type="audio/mp3" controls="controls"></audio>          </div><!-- @end .audio-player -->          </td>      </tr>  </tbody> 

and here js located in html file, inside body tag:

    <script type="text/javascript">         $(function(){             $('#audio-player').mediaelementplayer({             alwaysshowcontrols: true,             features: ['playpause','progress','volume'],             audiovolume: 'horizontal',             audiowidth: 450,             audioheight: 70,             ipadusenativecontrols: true,             iphoneusenativecontrols: true,             androidusenativecontrols: true             });         });     </script> 

i badly want use custom style(s).

i followed tutorial in styling audio player: http://designshack.net/articles/css/custom-html5-audio-element-ui/

basically, tried put audio player outside for each , styled fine. how come not working when inside looping?

i'm new knockout js please bear me. thanks.

odds seeing because when executing .mediaelementplayer() function before knockout has added audio players dom, there nothing style.

you defer evaluation if wanted, may still run timing issue. try using custom binding handler here -

<script type="text/javascript">     ko.bindinghandlers.audioplayer = {         init: function (element, valueaccessor) {         $(element).mediaelementplayer({             alwaysshowcontrols: true,             features: ['playpause','progress','volume'],             audiovolume: 'horizontal',             audiowidth: 450,             audioheight: 70,             ipadusenativecontrols: true,             iphoneusenativecontrols: true,             androidusenativecontrols: true         });     }; </script> 

which use in html -

<audio data-bind="audioplayer: {}" id="audio-player" src="media/evidence-song.mp3" type="audio/mp3" controls="controls"></audio> 

one note setting id inside foreach means multiple elements have exact same id - bad practice.


Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -