1

Wordpress 正在为画廊生成帖子的链接。

<ul>
<li><a href="/link/to/whatever" class="gallery-link">I Am A Gallery!</a></li>
<li><a href="/link/to/whatever-2" class="gallery-link">I Am Another Gallery!</a></li>
</ul>

我不希望链接转到帖子页面,而是将内容(.entry-content)加载到链接列表上方的 div(#result)中。

jQuery( document ).ready(function() {
    jQuery(".gallery-link").click(function() { 
        var $target = jQuery(this).attr("href"); //get the URL where the content is
        jQuery("#result").empty() // if the div has stuff in it, get rid of it
        jQuery("#result").css( { 'background-image': 'url(http://staging.caterernyc.com/wp-content/themes/caterer/images/ajax-loader.gif)', 'background-repeat': 'no-repeat', 'background-position': 'center', 'min-height': '200px'  } ); // show the loading gif while the .entry-content is being loaded

        jQuery("#result").load(this.href+" .entry-content", function() { // load the content
                    jQuery("#result").css('background-image', 'none');  // remove the loading gif
        });

        return false;
    });
});

可行,但我想做的是简化#result div 打开而不是刚刚出现的内容。我尝试过的任何方法都没有奏效。这甚至可能吗?我对这一切都错了吗?

4

1 回答 1

0

您可以尝试以下方法:

jQuery("#result").hide().load( url,function(){
  /* slide open once loaded*/
  $(this).slideDown();
});

无需使用empty()之前load()。现有内容正在被替换load()。还建议使用切换类而不是用.css(). 代码更干净更容易维护

于 2013-10-31T21:33:46.983 回答