Solved

jQuery before leaving a page (ASP MVC3 framework)

Posted on 2012-03-31
9
458 Views
Last Modified: 2012-04-12
Hey Experts,

I was wondering if it is possible to make some jQuery code run on the current page when a link to another page is clicked.

For instance, I have a menubar, and when someone clicks a link to another page, I want some elements to float off of the current page with jQuery's animate method before the other page loads.

I'm using the ASP.NET MVC3 framework.

Is it possible to do this?

Also, is it possible to change the javascript methods that are run depending on which page is going to another page? For instance, some code will only run if the person is on the home page and is loading the Contact page.

Thanks,

-Jeff
0
Comment
Question by:jeffiepoo
  • 4
  • 2
9 Comments
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 500 total points
ID: 37792546
You need to change the default behaviour of a link
http://api.jquery.com/animate/

$('#clickme').click(function(e) {
  $('#book').animate({
    opacity: 0.25,
    left: '+=50',
    height: 'toggle'
  }, 5000, function() {
    location = $(this).attr("href");
  });
  return false;
});
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 37792553
That will likely leave the page immediately!
0
 
LVL 6

Author Comment

by:jeffiepoo
ID: 37819017
I've requested that this question be deleted for the following reason:

No solutions, and this wasn't helpful
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 37818363
"No solutions, and this wasn't helpful" - was even less helpful.

Perhaps you could respond to suggestions detailing the issue you have with the code and we can help you better?

Did you even try my suggestion?
0
 
LVL 21

Expert Comment

by:Dale Burrell
ID: 37819018
Mplungjan suggestion is certainly a good starting point, and without additional feedback could easily be the solution. Points should be awarded.
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 37819031
I am fine with no points, but the closing comments was not very nice.
0
 
LVL 21

Expert Comment

by:Dale Burrell
ID: 37840216
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Learn by example how to specify CSS selectors for Selenium WebDriver test automation software.
Color can increase conversions, create feelings of warmth or even incite people to get behind a cause. If you want your website to really impact site visitors, then it is vital to consider the impact color has on them.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question