2013-02-26 116 views
0

我想添加两个粘贴(向上和向下)页面中间的arroys,可以滚动一个网页分为几个部分。所以箭头始终位于第二部分到最后一部分的中间,并让页面向上或向下滚动。jquery sticked向上和向下箭头向上和向下

enter image description here

目前,我有一个按钮,带我到网页

.content-wrap section .back-to-top { 
    display: block; 
    position: absolute; 
    bottom: -65px; 
    right: 10px; 
    height: 36px; 
    width: 36px; 
    background: url(http://www.caddet-re.org/assets/images/Arrow_Circle_Up.gif); 
    text-indent: -9999px; 
    z-index: 2; 
} 
<a class="back-to-top" href="#main">Back to Top</a> 

顶给我:

enter image description here

the jsfiddle is this

的STRU该部分的cture是:

<div class="content-wrap"> 
    <section id="main"> 
     <!--content--> 
     </section> 

     <section id="portfolio"> 
     <!--content--> 
    </section> 
     ... 
</div> 

回答

1

我已经改变了你的代码一点点:

http://jsfiddle.net/BorisDutkin1982/ZapgY/1/

我希望这是你的意思。您还可以添加“向下”按钮: 只需确保它位于“箭头容器”内,并且css参数为 与“向上”按钮相同,但top:45%除外,请将其更改为bottom:45%

如果您希望仅在第二节后显示箭头,则需要为“滚动”添加一个事件侦听器,并检查用户在哪里滚动页面。

$(document).ready(
    function(){ 
     $("body").live(
     "scroll", 
      function(){ 
      if($("body").scrollTop == NUMBER_OF_PIXELS_FROM_TOP_OF_THE_PAGE){ 
       $("arrow").show(); 
      } 
      } 
    ); 
    } 
); 

Explanaition: 您可以scrollTop()方法... 一种示例代码做我添加滚动动作,以“身体”的听众。每当用户页面顶部的距离是第二部分的位置时,用户将滚动正文/页面 - 显示ARROA

+0

有没有什么方法可以在第二部分之后显示箭头?我的意思是,在#部分#中没有显示箭头,之后它们显示出来... like'if($('selector')。hasClass('main')) { $(this).removeClass (“主要”); $(this).addClass(“hidden”); }'是否正确? – cMinor 2013-02-26 16:14:22

+0

我更新了答案:-) – BorisD 2013-02-27 06:11:11

相关问题