2015-10-14 73 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按钮在导航后似乎不一样。

似乎某些导航或重新呈现的页面会重写一个新按钮。

确保您的函数在每个页面呈现或导航中被调用。

相关问题