2016-07-31 104 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> 

它現在的作品。