2013-04-09 49 views
0

我正在設計一個小型站點,其中的標題將具有與其他頁面不同的高度/位置(頁面X & Y)。我想使用.animate來動態改變樣式,只有當用戶從索引轉到頁面X或Y時,而不是當用戶在頁面之間轉換時X & Y.只從索引頁面獲取Jquery .animate

如何使用JQuery來確定哪些用戶所在的頁面,並且僅在用戶從索引到X或Y時啓動動畫?

CSS,部首:

header { 
width: 100%; 
padding: 4% 0 10px; 
} 

指數標題:

.index header { 
position: absolute; 
top: 130px; 
} 

X &Ÿ標題:

.work header, .bio header { 
padding-top: 2%; 
} 
+0

嘗試讀取從地址欄的頁面URL – 2013-04-09 04:46:19

回答

0

確定你是從使用引薦來的頁面,如果你是來自索引,然後檢查僅存在於X上的元素或Y

$(document).ready(function() { 
    var referrer = document.referrer; 
    if(/*do custom check on referrer to see if you are coming from index */) 
    { 
     // to check if you are on X or Y 
     if($(".work").length || $(".work").length){ 
      // trigger animation 
     } 
    } 

}); 
0

嘗試

$(function() { 
    if (/index.html/.test(document.referrer)) { //Use your index page url in the regex instead of index.html 
     //do your animation 
    } 
});