出于某种原因,我无法通过javascript初始化时显示滚动条,但我可以通过html初始化。
滚动条应显示在#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初始化完成。
答案 0 :(得分:0)
好的,因为滚动条位于一个只在打开灯箱/模态窗口后出现的div中,我不得不将以下内容添加到我的脚本中:
live: true
所以,完整的,javascript函数是这样的:
<script>
(function($){
$(window).on("load",function(){
$("#popup-scroll").mCustomScrollbar({
scrollInertia: 0,
live: true
});
});
})(jQuery);
</script>
现在有效。