【问题标题】:Hide div in fancybox but show on normal page在fancybox中隐藏div但在普通页面上显示
【发布时间】:2016-08-04 10:13:39
【问题描述】:

我正在尝试做的是以下内容。

我的 wordpress 页面上有一个链接,可以打开一个花式框窗口并显示内容。没有页眉/页脚或任何内容,只是带有缩略图的内容。

但是,这是我的问题,我也希望访问者能够像往常一样访问该页面。但是现在有了页眉/导航/页脚以及您通常会在网页上看到的所有内容。

我尝试使用媒体查询(fancybox 窗口为 900x700),但没有奏效。我尝试了一些javascript:

$(window).resize(function() {

  if ($(this).width() < 1024) {

    $('.single-incl-opt-out').hide();

  } else {

    $('.single-incl-opt-out').show();

    }

});

还是不走运!

有谁知道我可以做些什么来让它工作?

更新: 一些代码示例。

我如何加载我的 fancybox 内容:

<?php echo get_the_term_list_inclusief( $post->ID, 'inclusief', '<p class="extra-text"><i class="fa fa-check"></i>&nbsp;', '<br><i class="fa fa-check"></i>&nbsp;', '</p>'); ?>

一些 CSS 不起作用:

@media only screen and (max-width:85em) and (min-width:50em) { 
    .fancybox-inner .single-incl-opt-out {display: none;}
}

当我改变我的主窗口大小时,CSS 可以工作,但不像我想要的那样在 fancybox 窗口中。

这里是执行fancybox的函数:

function get_the_term_list_inclusief( $id, $taxonomy, $before = '', $sep = '', $after = '') {
    $args_incl = array('order' => 'ASC');

    $terms = wp_get_object_terms( $id, $taxonomy, $args_incl );

    if ( is_wp_error( $terms ) )
        return $terms;


    if ( empty( $terms ) )
        return false;

    $links = array();

    usort($terms, function($a, $b) {
        return strcmp($a->name, $b->name);
    });

    foreach ( $terms as $term ) {
        $link = get_term_link( $term, $taxonomy, $args_incl );
        if ( is_wp_error( $link ) ) {
            return $link;
        }

        $links[] = '<a class="fancybox-incl fancybox.ajax" title="inclusief" href="' . esc_url( $link ) . '" rel="tag">' . $term->name . '</a>';
    }

单[post-type].php的代码:

<?php get_header(); ?>
<?php the_post(); ?>

<script>
$(window).resize(function() {

  if ($(this).width() < 1024) {

    $('.single-incl-opt-out').hide();

  } else {

    $('.single-incl-opt-out').show();

    }

});
</script>


<section id="inclusief" style="margin-top:15px;">
        <div class="col-sm-5 mobile">
            <h1 class="extra-title"><?php the_title(); ?></h1>
                <div class="tabcontent" id="tab-<?php the_ID(); ?>">
                    <p><?php the_content(); ?></p>
            </div>
        </div>
        <div class="col-sm-1"></div>
        <div class="col-sm-6 no-padding">
            <div class="incl">
                <?php if ( has_post_thumbnail() ) { the_post_thumbnail(); } ?>
            </div>
        </div>
</section>

【问题讨论】:

  • 所以你想只显示小屏幕的小内容,而普通屏幕的全部内容?
  • 是的,也不是。我希望小内容仅显示在 fancybox 窗口中,而整个内容显示在普通屏幕中。
  • 你能分享一些代码来重现这个问题吗?
  • 所以解决方案是引用一个css文件,该文件隐藏所有内容,但小屏幕的fancybox,反之亦然。
  • 你是如何加载fancybox中的内容的?你应该隐藏不需要的 div 然后 .. 而不是页面本身,如果你能向我们展示一些我可能能提供帮助的代码。祝你好运。

标签: javascript jquery html css wordpress


【解决方案1】:

您当前基于媒体查询和窗口大小隐藏内容的方法对移动设备不太友好,而且 FancyBox 似乎已经支持这一点,因为它使用的是 jQuery 的 ajax 方法。更多信息在这里:http://www.w3schools.com/jquery/jquery_ajax_load.asp

更新加载 FancyBox 的 PHP 函数,以在其中包含要加载的 div 的 id:

$links[] = '<a class="fancybox-incl fancybox.ajax" title="inclusief" href="' . esc_url( $link ) . '#inclusief" rel="tag">' . $term->name . '</a>';

可以在此处找到类似的问题/答案:Jquery FancyBox target specific DIV ID?

【讨论】:

  • 感谢您的链接。然而。我不是编码员。无论如何,您或其他人可以帮助我解决这个问题吗?首先加载链接的显示方式:&lt;?php echo get_the_term_list_inclusief( $post-&gt;ID, 'inclusief', '&lt;p class="extra-text"&gt;&lt;i class="fa fa-check"&gt;&lt;/i&gt;&amp;nbsp;', '&lt;br&gt;&lt;i class="fa fa-check"&gt;&lt;/i&gt;&amp;nbsp;', '&lt;/p&gt;'); ?&gt; 然后应用该功能? $(".extra-text").on('click', function(event) { $('#show_style').load(this.href + " #inclusief").fancybox(); }); 那会是这样吗?
猜你喜欢
  • 2013-02-16
  • 1970-01-01
  • 2020-06-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-08-31
  • 2023-04-05
  • 1970-01-01
相关资源
最近更新 更多