简体   繁体   English

滚动div(固定)以再次滚动

[英]Scrolling div, to fixed, to scroll again

I have a page layout where a full width image is at the top, then on the right there is text content. 我有一个页面布局,其中全角图像在顶部,然后在右侧是文本内容。 On the left, there is a small scrolling div with social links in. 左侧是一个带有社交链接的小滚动div。

It's like this: http://blog.teamtreehouse.com/building-a-jquery-sticky-sidebar-navigation-menu (social links scroll, then become fixed, then scrolls from another div). 就像这样: http : //blog.teamtreehouse.com/building-a-jquery-sticky-sidebar-navigation-menu (社交链接滚动,然后变得固定,然后从另一个div滚动)。

Here is an example, but without the final piece of the puzzle below: http://jsfiddle.net/nwFrg/ 这是一个示例,但没有以下难题的最后一部分: http : //jsfiddle.net/nwFrg/

            function sticky_relocate() {
          var window_top = jQuery(window).scrollTop();
          var div_top = jQuery('#e-c-r-top').offset().top ;
          if (window_top > div_top)
            jQuery('.socialbar-left').addClass('fixedsocialbar')
          else
            jQuery('.socialbar-left').removeClass('fixedsocialbar');
          }
        // If you have jQuery directly, use the following line, instead
         jQuery(function() {
        // If you have jQuery via Google AJAX Libraries
        // google.setOnLoadCallback(function() {
          jQuery(window).scroll(sticky_relocate);
          sticky_relocate();
          });

When we get to the red footer, I want the 'hello box' to stop and stay there, aligned to bottom (until the person scrolls up again, then all should happen in reverse again. 当我们到达红色页脚时,我希望“ hello框”停下来并停留在那里,并与底部对齐(直到该人再次向上滚动,然后所有操作都应反向进行。)

If someone can help tell me with the js to go from scrolling, to fixed (which is already in my example) and then a third trigger for bottom, i already know the css that will align it to bottom, just need the js trigger. 如果有人可以帮助我告诉我js从滚动到固定(这已经在我的示例中),然后是底部的第三个触发器,我已经知道将其与底部对齐的css,只需要js触发器即可。

I hope I've explained this OK. 我希望我已经对此进行了解释。

You probably don't need to bother with the whole fixed/scroll switch. 您可能不需要理会整个固定/滚动开关。 Instead, have the javascript limit the upper and lower end of the range. 相反,让javascript限制范围的上限和下限。 If the user scrolls past either end, just ignore those numbers and use the min/max instead. 如果用户滚动到任一端,则只需忽略这些数字,而使用最小值/最大值。 (You can get the min/max by reading the position of the appropriate elements on the page.) (您可以通过读取页面上适当元素的位置来获得最小值/最大值。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM