2016-07-31 102 views
0

出于某种原因,我无法通过javascript初始化时显示滚动条,但我可以通过html进行初始化。mCustomScrollbar禁用滚动动画

滚动条是为了出现在#popup-scroll里面,它有php的内容。这是一个库中的所有内容,弹出窗口充当循环中每个项目的灯箱。

 <?php 
    $the_query = new WP_Query(array(
    'post_type' => 'post')); while ($the_query->have_posts()) : $the_query->the_post();?> 
    <?php 
     echo'<figure><a class="popup-with-zoom-anim" href="#'.$post->post_name.'">'.the_post_thumbnail().'<div class="title"><h2>'.$post->post_title.'</h2></div></a></figure>'; 

    echo'<div id="'.$post->post_name.'" class="zoom-anim-dialog mfp-hide"> 
<div id="popup-scroll">'.$content.'</div></div>'; ?> 

    <?php endwhile; wp_reset_postdata(); ?> 

由JavaScript初始化(不工作):

<script> 
    (function($){ 
     $(window).on("load",function(){ 
      $("#popup-scroll").mCustomScrollbar({scrollInertia: 0}); 
     }); 
    })(jQuery); 
</script> 

通过HTML初始化(作品):

<div id="popup-scroll" class="mCustomScrollbar" data-mcs-theme="dark"> 
    <!-- the content --> 
</div> 

目标是禁用滚动动画scrollInertia: 0,只能通过JavaScript初始化完成。

The developer site, for reference

回答

0

好,因为滚动条是只出现一次打开灯箱/模态窗口,我不得不以下内容添加到我的脚本一个div:

live: true 

所以,在完整的JavaScript功能是这样的:

<script> 
    (function($){ 
     $(window).on("load",function(){ 
      $("#popup-scroll").mCustomScrollbar({ 
       scrollInertia: 0, 
       live: true 
      }); 
     }); 
})(jQuery); 
</script> 

它现在的作品。