Dynamically load WordPress content using ajax and incorporate CSS3 animations for added visual appeal

It's time for a new challenge to push my learning curve. I've never ventured into the world of ajax before, but it seems like a skill I need to acquire. What better opportunity to learn than by implementing it on a fresh portfolio site.

The main idea behind this website is to have content slide behind folds at the edges of the 960 grid. Clicking on a link causes the current content to slide out into its respective fold, which then adjusts in size to accommodate new content blocks sliding in from under the folds. I've managed to achieve this somewhat with news using the Wordpress loop and basic jquery, although adjusting fold height remains a challenge as new content loads.

I'm starting with this (http://www.deluxeblogtips.com/2010/05/how-to-ajaxify-wordpress-theme.html) as a foundation, but it doesn't quite meet my vision.

Instead of setting up a jsfiddle, here's how the site currently looks

EDIT: Apologies for rambling without posing a question:

How can I create a sequence where clicking on an internal link triggers these events:

Content box slides out -> Content changes -> Fold expands -> New content slides in

EDIT 2: Upon reflection, I realize I haven't been clear again. While I understand loading content via ajax, my struggle lies in handling different page layouts. For instance:

The homepage features three recent projects sliding down from a top fold, a news post sliding in from the left, and a list of news posts sliding in from the right.

The Work/Play pages display blocks sliding down from a top fold.

Contact consists of full-width folds filling the 960 grid. The same layout applies to the about page, though there might be a sidebar added later.

How can I enable AJAX to recognize the current loaded content and adjust accordingly?

Thank you in advance for any assistance!

Answer №1

You have a clear idea of what needs to be done, so here is an untested outline on how to make it work.

 function animateInDone () {
      // implement actions here
 }

 function foldReady () {
      // scale the fold for the content and display it on screen
      $('#contentBox').animate(
           {'left':'100px'},
           400,
           'swing',
           complete: animateInDone
      );
 }

 function contentLoadDone (responseText, textStatus, XMLHTTPStatus) {
      // new content loaded and displayed in div using .load()
      if (textStatus == 'success') {
           // adjust the fold size
           $('#fold').animate(
                {height:'350px'}, 
                400, 
                'swing', 
                foldReady
           );
      } else {
           // handle errors
      }
 }

 function animateOutDone () {
      // load new content using .load or .ajax
      $('#contentBox').load(
           'newcontent.html',
           complete:contentLoadDone
      );
 }

 function contentChange () {
      // animate the content box out
      $('#contentBox').animate(
           {'left':window.innerWidth},
           400,
           'swing',
           complete: animateOutDone
      );
 }

If you need details on the exact syntax for the .animate call, refer to the documentation links below:

In addition to EDIT 2: You should maintain the UI state somewhere, like using a variable to store the current page or creating a class hierarchy with different UI animations for each page.

var pageHome = function () {
    this.animIn = function () {
       // animate home page in
    }

    this.animOut = function (newpage) {
       // animate home page out and set newpage.animIn as the callback after animation
    }
}

var pageNow = pageHome;
pageNow.animIn();

I personally find function objects quite useful.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Refresh iOS / iPad website only upon scrolling, not when utilizing anchor links

Currently, I am in the process of troubleshooting this website: This site is hosted on a LAMP server and is utilizing CMSMS 2.1x, if that detail makes any difference. (By the way, the smarty components are causing some performance issues.) While the desk ...

What is the solution to prevent a CSS flex column from expanding to fill the width in a row with three

I am trying to create a flex row with three columns, but when I only have two columns in the row, the second column gets pushed to the right side. You can see this issue in the image below. https://i.sstatic.net/cVVqB.png In the image, the red lines indi ...

How can I show the real width of an image on a mobile device?

I have integrated the infinite slide plugin from jQueryscript.net into my website. While it works perfectly on desktop with background images, I am facing an issue on mobile devices where the image width needs to be displayed in full. I attempted to adjust ...

Execute JavaScript function after the reset button has been clicked

Is there a way to execute a function right after the form elements are reset by the <input type="reset"/> button? ...

The checkbox is failing to display as checked even after its value has been dynamically set to true

Currently, I am immersed in a project within ASP.NET MVC that involves displaying data on a page where users can interact by selecting checkboxes to make changes. In cases where there are numerous checkboxes present, a "Select all Checkboxes" button become ...

Saving downloaded web pages as an HTML document

I'm looking to extract the HTML content of a webpage. Within this HTML, there are two specific elements with XPaths that I need to retrieve. Unfortunately, my knowledge on this subject is quite limited. While searching for solutions, most examples in ...

The continuation of unraveling the mystery of utilizing `overflow-y:scroll` in a horizontal slider

As a beginner, I realized too late that adding code in comments is not an option. Consequently, I decided to create a new question and ask for your assistance once again. To optimize the use of space, I have implemented bxSlider with fixed dimensions (wid ...

steps for setting up an endless scroll masonry grid

I have incorporated masonry js to display content on my website. Now, I am interested in adding infinite scrolling functionality using this script. I came across a demo that showcases this feature. However, I am struggling to figure out how to implement ...

Element widths are displaying uneven alignment

I can't seem to wrap my head around what's happening here. I've got an HTML layout with a header, sidebar, and central content page. Both the sidebar and central content are within the same div acting as a clearfix. I floated the sidebar le ...

What is the best way to customize the icon-bar in react-bootstrap's Navbar?

I am trying to customize the icon-bar in a react-bootstrap's Navbar component by setting its background color to white. However, my webpack scss loader is preventing me from styling CSS classes with dashes, as it only allows camel case. This restricti ...

Adding a button input and deleting non-functional parent elements

Here is a simple append function using jQuery, and it's working perfectly. However, the issue arises when I try to append a button and remove the parent tr upon clicking. The problem lies in using remove parent, as it doesn't seem to work as exp ...

Switching views in AngularJS by using a controller to control the content displayed in the

My JavaScript web app utilizes AngularJS to simplify tasks, but I've encountered an issue. I'm trying to change views from an ng-controller using $location.path, but for some reason, the view isn't updating even though the path in the $loca ...

Experience unique website functionalities across Windows/Android and Apple ecosystems

Apologies for any language errors in advance. I'm facing an issue where my website appears differently on Safari or Chrome on iOS/MacOS compared to Windows 10 or Android devices. If you observe the List of Receiving Countries in the images provided: ...

Working with arrays of multiple checkboxes in jQuery

<input type="checkbox" name="options[]" value="1" /> <input type="checkbox" name="options[]" value="2" /> <input type="checkbox" name="options[]" value="3" /> <input type="checkbox" name="options[]" value="4" /> <input type="chec ...

Is there a way to alter the appearance of an HTML element without an ID using a JavaScript function?

I have a specific goal in mind, but I'm struggling to articulate it concisely. Despite conducting extensive research, none of the suggested solutions seem applicable in my case. Objective: I aim to change the background color of a div based on the da ...

It is not possible to simultaneously utilize the properties `display: inline-block` and `width: 100%`

As someone with limited CSS knowledge, I have encountered a challenge. My goal is to ensure that my website's body has a width of 100%, while also preventing the content from wrapping when the browser window is resized. To achieve this, I attempted a ...

How to Build a Number Spinner Using Angular Material?

Is there a number spinner in Angular Material? I attempted to use the code provided in this question's demo: <mat-form-field> <input type="number" class="form-control" matInput name="valu ...

Ways to enlarge the diameter of the inner circle

I've implemented some CSS with JQuery, as seen in this JSFiddle. However, I'm having trouble increasing the width and height of the green circle to be slightly larger than the gray circle (referred to as the main circle) which is positioned at a ...

Laravel 4 not receiving data from Angular $http PUT request in 'multipart/form-data' format

Hello there! I am currently working with a RESTful API created in Laravel 4 and using Angular.js for handling tasks on the frontend. The main goal is to allow users to create a new 'item' in the database by submitting form data via POST request ...

PHP unable to display HTML form element using its designated ID attribute

I've been experiencing some difficulties with PHP echoing a label element that contains an ID attribute within an HTML form. My intention was to utilize the ID attribute in order to avoid having to modify the JS code to use the name attribute instead. ...