• Jetzt anmelden. Es dauert nur 2 Minuten und ist kostenlos!

Stickyjs unten anstatt oben

derises

Mitglied
Hallo,

ich würde gerne dieses Plugin benutzen, habe allerdings noch nicht herausgefunden wie ich die Navigation unten positionieren kann.

Link: http://stickyjs.com/

bottomSpacing: 0 ändert leider nichts....

Grüße und vielen Dank, derises
 
Werbung:
Hier auf JSFiddle: http://jsfiddle.net/VfZJT/

Einfach mal nach unter scrollen, der Header bleibt oben stehen - ich will aber haben, dass dieser unten stehen bleibt und nicht oben.
Hoffe das ist verständlich.
Leider tut sich nichts trotz bottomSpacing:50, was mache ich nur falsch?

EDIT:
Hier noch die verfügbaren Optionen:
Code:
Options

topSpacing: Pixels between the page top and the element's top.
bottomSpacing: Pixels between the page bottom and the element's bottom.
className: CSS class added to the element and its wrapper when "sticked".
wrapperClassName: CSS class added to the wrapper.
getWidthFrom: Selector of element referenced to set fixed width of "sticky" element.
 
Werbung:
Code:
$(document).ready(function(){
    $("#header").sticky({topSpacing:$(window).height()-$("#header").height()});
  });

iwie so müsste es doch gehen...
 
Eine Frage hat sich mir nun doch noch eröffnet und zwar, ist es möglich bzw. wie das die "Navigation" bzw. das Element von Anfang an unten angezeigt wird und nicht erst nach dem scrollen?

Grüße & Danke im voraus für jegliche Hilfe.

StickyJS:
Code:
// Sticky Plugin v1.0.0 for jQuery
// =============
// Author: Anthony Garand
// Improvements by German M. Bravo (Kronuz) and Ruud Kamphuis (ruudk)
// Improvements by Leonardo C. Daronco (daronco)
// Created: 2/14/2011
// Date: 2/12/2012
// Website: http://labs.anthonygarand.com/sticky
// Description: Makes an element on the page stick on the screen as you scroll
//       It will only set the 'top' and 'position' of your element, you
//       might need to adjust the width in some cases.

(function($) {
  var defaults = {
      topSpacing: 0,
      bottomSpacing: 0,
      className: 'is-sticky',
      wrapperClassName: 'sticky-wrapper',
      center: false,
      getWidthFrom: ''
    },
    $window = $(window),
    $document = $(document),
    sticked = [],
    windowHeight = $window.height(),
    scroller = function() {
      var scrollTop = $window.scrollTop(),
        documentHeight = $document.height(),
        dwh = documentHeight - windowHeight,
        extra = (scrollTop > dwh) ? dwh - scrollTop : 0;

      for (var i = 0; i < sticked.length; i++) {
        var s = sticked[i],
          elementTop = s.stickyWrapper.offset().top,
          etse = elementTop - s.topSpacing - extra;

        if (scrollTop <= etse) {
          if (s.currentTop !== null) {
            s.stickyElement
              .css('position', '')
              .css('top', '');
            s.stickyElement.parent().removeClass(s.className);
            s.currentTop = null;
          }
        }
        else {
          var newTop = documentHeight - s.stickyElement.outerHeight()
            - s.topSpacing - s.bottomSpacing - scrollTop - extra;
          if (newTop < 0) {
            newTop = newTop + s.topSpacing;
          } else {
            newTop = s.topSpacing;
          }
          if (s.currentTop != newTop) {
            s.stickyElement
              .css('position', 'fixed')
              .css('top', newTop);

            if (typeof s.getWidthFrom !== 'undefined') {
              s.stickyElement.css('width', $(s.getWidthFrom).width());
            }

            s.stickyElement.parent().addClass(s.className);
            s.currentTop = newTop;
          }
        }
      }
    },
    resizer = function() {
      windowHeight = $window.height();
    },
    methods = {
      init: function(options) {
        var o = $.extend(defaults, options);
        return this.each(function() {
          var stickyElement = $(this);

          var stickyId = stickyElement.attr('id');
          var wrapper = $('<div></div>')
            .attr('id', stickyId + '-sticky-wrapper')
            .addClass(o.wrapperClassName);
          stickyElement.wrapAll(wrapper);

          if (o.center) {
            stickyElement.parent().css({width:stickyElement.outerWidth(),marginLeft:"auto",marginRight:"auto"});
          }

          if (stickyElement.css("float") == "right") {
            stickyElement.css({"float":"none"}).parent().css({"float":"right"});
          }

          var stickyWrapper = stickyElement.parent();
          stickyWrapper.css('height', stickyElement.outerHeight());
          sticked.push({
            topSpacing: o.topSpacing,
            bottomSpacing: o.bottomSpacing,
            stickyElement: stickyElement,
            currentTop: null,
            stickyWrapper: stickyWrapper,
            className: o.className,
            getWidthFrom: o.getWidthFrom
          });
        });
      },
      update: scroller,
      unstick: function(options) {
        return this.each(function() {
          var unstickyElement = $(this);

          removeIdx = -1;
          for (var i = 0; i < sticked.length; i++)
          {
            if (sticked[i].stickyElement.get(0) == unstickyElement.get(0))
            {
                removeIdx = i;
            }
          }
          if(removeIdx != -1)
          {
            sticked.splice(removeIdx,1);
            unstickyElement.unwrap();
            unstickyElement.removeAttr('style');
          }
        });
      }
    };

  // should be more efficient than using $window.scroll(scroller) and $window.resize(resizer):
  if (window.addEventListener) {
    window.addEventListener('scroll', scroller, false);
    window.addEventListener('resize', resizer, false);
  } else if (window.attachEvent) {
    window.attachEvent('onscroll', scroller);
    window.attachEvent('onresize', resizer);
  }

  $.fn.sticky = function(method) {
    if (methods[method]) {
      return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
    } else if (typeof method === 'object' || !method ) {
      return methods.init.apply( this, arguments );
    } else {
      $.error('Method ' + method + ' does not exist on jQuery.sticky');
    }
  };

  $.fn.unstick = function(method) {
    if (methods[method]) {
      return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
    } else if (typeof method === 'object' || !method ) {
      return methods.unstick.apply( this, arguments );
    } else {
      $.error('Method ' + method + ' does not exist on jQuery.sticky');
    }

  };
  $(function() {
    setTimeout(scroller, 0);
  });
})(jQuery);
 
Werbung:
dann brauchst du das ganze javascript doch gar nicht

einfach position: fixed;
und bottom: 0;

im css..
 
Eben nicht, das war der ursprünglich Ansatz.
Leider sieht das auf einem Windows Phone dann nicht so toll aus - dieses erkennt position:fixed nicht.
Mit dem Jquery Plugin klappt das, allerdings muss nun noch die Navigation immer unten angezeigt werden und nicht erst beim nach unten scrollen.

Die erste Navigation wurde nur mit CSS realisiert und mit position:fixed realisiert.

Grüße, derises
 
Zurück
Oben