2015-01-08 2 views
1

У меня есть один вопрос о моем прокрутке для исправленного плагина jquery.JQuery Прокрутка до фиксированного позиционирования при прокрутке вниз

Я создал этот DEMO из codepen.io

Вы можете видеть в этом примере, когда вы прокрутите вниз, то аватар фиксирована, а если прокрутить вверх проблема там положение .text дел. Как я могу исправить это, кто-нибудь может мне помочь?

+0

Это всегда хорошая идея, чтобы скопировать соответствующий код на вопрос. Прямо сейчас, если ваше перо кода удалено, никто другой не сможет воспользоваться этим вопросом. К счастью, @mateen предоставил код в одном из своих ответов, но это действительно должно быть частью вопроса. –

ответ

0

В прилагаемом jQuery есть метод «setFixed()», который устанавливает положение как position = 'fixed'; изменить его в положение = «относительно»

Реальная функция

function setFixed() { 
     // Only fix the target element and the spacer if we need to. 
     if (!isFixed()) { 
      // Set the spacer to fill the height and width of the target 
      // element, then display it. 
      spacer.css({ 
       'display' : target.css('display'), 
       'width' : target.outerWidth(true), 
       'height' : target.outerHeight(true), 
       'float' : target.css('float') 
      }); 

      // Set the target element to fixed and set its width so it does 
      // not fill the rest of the page horizontally. Also, set its top 
      // to the margin top specified in the options. 

      cssOptions={ 
       'z-index' : base.options.zIndex, 
       'position' : 'relative', 
       'top' : base.options.bottom == -1?getMarginTop():'', 
       'bottom' : base.options.bottom == -1?'':base.options.bottom, 
       'margin-left' : '0px' 
      } 
      if (!base.options.dontSetWidth){ cssOptions['width']=target.css('width'); }; 

      target.css(cssOptions); 

      target.addClass(base.options.baseClassName); 

      if (base.options.className) { 
       target.addClass(base.options.className); 
      } 

      position = 'fixed'; 
     } 
    } 

Изменения в

function setFixed() { 
     // Only fix the target element and the spacer if we need to. 
     if (!isFixed()) { 
      // Set the spacer to fill the height and width of the target 
      // element, then display it. 
      spacer.css({ 
       'display' : target.css('display'), 
       'width' : target.outerWidth(true), 
       'height' : target.outerHeight(true), 
       'float' : target.css('float') 
      }); 

      // Set the target element to fixed and set its width so it does 
      // not fill the rest of the page horizontally. Also, set its top 
      // to the margin top specified in the options. 

      cssOptions={ 
       'z-index' : base.options.zIndex, 
       'position' : 'relative', 
       'top' : base.options.bottom == -1?getMarginTop():'', 
       'bottom' : base.options.bottom == -1?'':base.options.bottom, 
       'margin-left' : '0px' 
      } 
      if (!base.options.dontSetWidth){ cssOptions['width']=target.css('width'); }; 

      target.css(cssOptions); 

      target.addClass(base.options.baseClassName); 

      if (base.options.className) { 
       target.addClass(base.options.className); 
      } 

      position = 'relative'; 
     } 
    } 
+0

благодарит за помощь, но вы все еще пытаетесь это сделать? Потому что он не работает ... – innovation

Смежные вопросы