0

我正在设计一个小型网站,其中标题的高度/位置与其他页面(页面 X 和 Y)不同。我想使用 .animate 仅在用户从索引转到页面 X 或 Y 时为样式更改设置动画,而不是当用户在页面 X 和 Y 之间移动时。

我如何使用 Jquery 来确定用户在哪个页面上,并且仅当用户从索引转到 X 或 Y 时才启动动画?

CSS,标题:

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

索引标题:

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

X & Y 标题:

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

2 回答 2

0

尝试

$(function() {
    if (/index.html/.test(document.referrer)) { //Use your index page url in the regex instead of index.html
        //do your animation
    }
});
于 2013-04-09T05:10:02.803 回答
0

使用 referrer 确定您来自的页面,如果您来自索引,然后检查是否存在仅在 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 
       }
   }

});
于 2013-04-09T04:57:27.420 回答