由于某些原因,我无法在通过javascript进行初始化时显示滚动条,但我可以通过html进行初始化。
滚动条应该出现在包含php内容的#popup-scroll中。这一切都在一个图库中,弹出式窗口充当循环中每个项目的灯箱。
<?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进行初始化(works):
<div id="popup-scroll" class="mCustomScrollbar" data-mcs-theme="dark">
<!-- the content -->
</div>目标是禁用滚动动画scrollInertia: 0,这只能通过javascript初始化来完成。
The developer site, for reference
发布于 2016-08-01 08:25:01
好的,因为滚动条在一个div中,只有在lightbox / modal窗口打开时才会出现,所以我必须在我的脚本中添加以下内容:
live: true因此,完整的javascript函数是这样的:
<script>
(function($){
$(window).on("load",function(){
$("#popup-scroll").mCustomScrollbar({
scrollInertia: 0,
live: true
});
});
})(jQuery);
</script>它现在起作用了。
https://stackoverflow.com/questions/38682078
复制相似问题