2015-10-14 72 views
1

我做了這個JQuery按鈕的layerslider插件。但該按鈕僅在加載頁面時起作用。當您瀏覽網站並返回到hoempage時,該按鈕不再有效。jquery靜音只適用於第一頁加載

有什麼建議嗎?

function(element) { 
    jQuery(document).on('click', '.mute-video', function(){ 
     if (jQuery("video").prop('muted')) { 
      jQuery("video").prop('muted', false); 
      jQuery(this).addClass('unmute-video'); 

     } else { 
      jQuery("video").prop('muted', true); 
      jQuery(this).removeClass('unmute-video'); 
     } 
    }); 
} 

HTML:

<video id="myVideo" width="100%" height="100%" autoplay loop > 
    <source src="/startransfer/wp-content/uploads/2015/10/StarTransfer-promo-aanhanger.mp4" type="video/mp4"> 

CSS:

.mute-video { 
    background:url(http://www.welzendesign.com/startransfer/wp-content/uploads/2015/10/volume47.png) no-repeat center; 
    background-size:42px; 
    background-color: rgba(0, 0, 0, 0.5); 
    border:0 !important; 
    width:64px; 
    height:64px; 
    text-indent:-999px; 
    bottom: 0px; 
    left: 0px; 
    text-decoration:none; 
} 
.unmute-video { 
    background:url(http://www.welzendesign.com/startransfer/wp-content/uploads/2015/10/volume47.png) no-repeat center; 
    background-size:42px; 
    background-color: rgba(0, 0, 0, 0.5); 
    border:0 !important; 
    text-decoration:none; 
} 

.unmute-video:focus, 
.unmute-video:active { 
    outline: none; 
} 

.mute-video:focus, 
.mute-video:active { 
    outline: none; 
} 

提前感謝!

+0

你會分享你的HTML嗎? –

+0

我編輯了我的文章 – Vonwelzen

+0

在哪裏應用這些CSS? –

回答

0

您在其中添加了click事件的.mute-video按鈕在導航後似乎不一樣。

似乎某些導航或重新呈現的頁面會重寫一個新按鈕。

確保您的函數在每個頁面呈現或導航中被調用。

相關問題