WordPress is generating the links to Posts for a gallery.
<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>
I don’t want the links to go to the post page but instead have the content (.entry-content) load in a div (#result) above the list of the links.
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;
});
});
This works but what I want to do is ease the #result div open instead of the content just appearing. Nothing I’ve tried yet has worked. Is this even possible? Am I going about this all wrong?
You could try something like:
No need to use
empty()
prior toload()
. The exisiting content is being replaced byload()
. Also suggest using toggling a class instead of replacing background with.css()
. It is cleaner and easier to maintain code