【问题标题】:Slick slider issue: Image not showing on initial load滑动滑块问题:初始加载时未显示图像
【发布时间】:2016-02-14 15:18:09
【问题描述】:

当我运行滑块时,没有显示初始图像。只有在我单击“下一步”按钮后,滑块才会开始起作用。

问题链接:http://zaaroinfotechsolutions.com/zaarodemo/longbeach/corporate/(点击历史标签并一直向下滚动)

这是我的代码: html

<div class="col-sm-9" style="padding:0px;"> <div class="main-slick">
                        <?php 
                               $args = array(
                                    'posts_per_page' => -1,
                                    'post_type' => 'slide',
                                    'tax_query' => array(
                                        array(
                                          'taxonomy' => 'slide_category',
                                          'field'    => 'slug',
                                          'terms'    => 'history'
                                        )
                                    )
                                  );
                                  $query = new WP_Query($args);

                                   while ($query->have_posts()) :
                                    $query->the_post();
                                    $feat_image_main = wp_get_attachment_url(get_post_thumbnail_id($post->ID));

                                ?>
          <img src="<?php echo wp_get_attachment_url(get_post_thumbnail_id($post->ID));          ?>" class="img-responsive mainimage" id="mainimage">
<?php endwhile; ?> </div> </div>

Javascript

$(document).ready(function(){ 
  $('.main-slick').slick( { infinite: false});
});

【问题讨论】:

    标签: javascript html css wordpress slick.js


    【解决方案1】:

    在我的项目中,slick('setPosition') 不起作用,但上面带有 slick('refresh') 的代码起作用了,所以我使用了:
    $('.main-slick').slick('refresh');

    【讨论】:

      【解决方案2】:

      在历史标签可见后,您需要手动刷新 Slick 插件的位置。将此添加到您的 javascript:

      $(document).ready(function () {
        $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
          $('.main-slick').slick('setPosition');
        });
      });
      

      Working Plunker

      【讨论】:

        【解决方案3】:

        在第一次访问时对我来说工作正常,然后在下次访问时出现问题。我怀疑缓存错误?

        【讨论】:

        • 是的,我也意识到了!对原因有任何想法吗?
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2021-01-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-12-12
        相关资源
        最近更新 更多