试图使一个已经可点击的div打开fancybox

时间:2013-03-15 18:23:05

标签: javascript wordpress fancybox

我不是一个程序员。只是通过wordpress自学。我有一个网站,我从一个空白的主题一起入侵,我已经把它拿走了很远。

我想要做的最后一步是让我的#brick打开永久链接页面,其中包含relclass的fancybox。

使用WP fancybox插件。

这是我正在做的事情,使div可以在第一时间点击

<div id="brick" onclick="location.href='<?php the_permalink(); ?>';" style="cursor:pointer;">

我会在此行中添加rel="fancybox"class="fancybox"

提前谢谢。

2 个答案:

答案 0 :(得分:0)

可以直接向元素添加relclass属性:

<div id="brick" onclick="location.href='<?php the_permalink(); ?>';" style="cursor:pointer;" rel="fancybox" class="fancybox">

JavaScript可能是:

$("div.fancybox").fancybox();

或您想要使用的任何选择器。由于您可以使用classidtag name的组合来选择jQuery。

答案 1 :(得分:0)

由于您的href代码中已经设置了<a>,例如代码的这一部分。

<h2 class="entry-title"><a rel="bookmark" title="Permalink to Art and commerce in the digital age" href="http://throughthelattice.com/art-and-commerce-in-the-digital-age/">Art and commerce in the digital age</a></h2>

...然后,我会这样做:

  1. 删除此行

    <script src="//throughthelattice.com/wp-content/themes/lh_wordpress_blank_theme/js/jquery-1.7.1.min.js"></script>
    

    ...您已在<head>部分

  2. 中加载了jQuery v1.8.3
  3. 将所有id="brick"替换为class="brick"

  4. 替换此脚本

    <script>
    $('#brick').fancybox();
    </script>
    

    ...由此:

    <script>
    jQuery(document).ready(function () {
        jQuery("a[rel='bookmark']").fancybox({
            "type": "iframe"
        });
    }); // ready
    </script>
    
  5. 参见 JSFIDDLE

相关问题