0

I have a very basic jQuery script that slides a title from bottom to top after the page loads. The problem I'm having now is that I need to make this title to only slide if the user is on the 'main page'. If the user then clicks on any sub-pages I need the title to remain to the top of the page.

Example: wordpress website with a few pages on which I have galleries. When a user enters a page -> animate title. When the user is browsing the gallery -> static title.

This is the jQuery script:

jQuery(document).ready(function () {
jQuery(".animate").addClass("move"); 
});

You can see the website in question here.

// later edit: Thanks everyone for helping! I forgot to mention that I have multiple URLs, there are multiple pages. Is there a way I can get the "current URL" of the page and then append to it the extra bit which will always be the same i.e. /?pid=xx ?

Example: I need to animate the title on pages with this format:

mywebpage/custom_name/

Then, on pages with this format, I need to keep the title static:

mywebpage/custom_name/?pid=xx

Following the answers bellow I made this script:

if(window.location.href == 'http://www.noahd.net/demo-upwall/residential/rooftop-garden/'){
    jQuery(document).ready(function () {
        jQuery(".animate").addClass("move"); 
    });
} else {
    jQuery(document).ready(function () {
        jQuery(".portfolio-title-wrap").removeClass("animate").addClass("top"); 
    }); 
}

This script works only for the /residential/rooftop-garden/ page. Under residential I have another 10 pages. And then I have another 6 pages starting from root, like /commercial/ or /objects which also have 6-10 sub-pages.

How can I adapt the above script to work on those pages and sub-pages but not on the sub-sub-pages?

4

3 回答 3

1

您可以根据 url 决定页面的行为。

代码:

if(window.location.href== mainapplicationurl){

    // slide code
}
else{
      // put title on top

}

编辑问题后。您可以根据 url 中“/”的计数来决定页面(仅当 url 格式一致时才有效)。

var count = window.location.href.split("/").length;
jQuery(document).ready(function () {
   if( count < 7 ){        
        jQuery(".animate").addClass("move"); 
   } else {        
        jQuery(".portfolio-title-wrap").removeClass("animate").addClass("top"); 
    }
});
于 2012-10-10T19:23:01.370 回答
1

Wordpress 使用独特的类标记页面,因此您可以像这样定位特定页面:

jQuery(document).ready(function () {
    jQuery(".page-id-32 .animate").addClass("move"); 
});
于 2012-10-10T19:27:21.407 回答
0

你可以用不同的方式来做。例如,您只能在使用 wordpress 条件的特定页面上加载幻灯片标题内容。

或者你可以从客户端做你想做的事。例如,您的页面有不同的标题标签,而主页有 - Upwall Studio,您可以检查:

if ($('title').text() === 'Upwall Studio') {
  //slide youre title here
}

或者您可以通过 window.location.href 检查用户是否在特定 url 上:

if (window.location.href === 'http://www.noahd.net/demo-upwall/') {
  //slide youre title here
}
于 2012-10-10T19:29:29.133 回答