javascript - Choppy animation on scroll -


i'm attempting animate block based on how far scrolled down page am, using jquery change css attribute.

when using mouse wheel, there slight flicker of , ends being shown @ same time.

an example of can viewed @ following link.

http://fiddle.jshell.net/lpves/10/show/light/

this behaviour not smooth , feels 'choppy'.

i have no idea why happening. expected behaviour should this:

http://jsfiddle.net/lpves/10/embedded/result/

i understand irony of linking exact same example. difference can see between 2 1 embedded in iframe, not solution want use.

my js code:

var icons = {     header: "iconclosed",     activeheader: "iconopen" };  $('.main--content').accordion({     header: ".accordion header",     heightstyle: "content",     collapsible: true,     icons: icons });  function accordionicon() {      var icon = $('.ui-accordion-header-icon.iconopen');     var iconclosed = $('.ui-accordion-header-icon.iconclosed');      if (icon[0]) {         var article = $('.ui-accordion-header-icon.iconopen').closest('.article')          if (article.offset().top - window.scrolly > 200) {              if (icon.css('top') !== 0) {                 icon.css('top', 0)             }          } else if (article.offset().top - window.scrolly < 200) {             // article.outerheight() - (icon.offset().top - article.offset().top) > 0             if (article.offset().top - (window.scrolly + 200) < article.outerheight() && window.scrolly + $(window).height() - article.offset().top < article.outerheight()) {                  var position = (window.scrolly + 200) - article.offset().top                  // if(icon.css('transform') === none){                 icon.css('top', position)                 // }                  if (icon.hasclass('iconextend')) {                     icon.removeclass('iconextend')                 }              } else if (window.scrolly + $(window).height() - article.offset().top > article.outerheight()) {                  if (icon.css('top') !== article.outerheight() + 30) {                     icon.css('top', article.outerheight() + 30)                 }                  if (!icon.hasclass('iconextend')) {                     icon.addclass('iconextend')                 }              } else {                  if (icon.css('top') !== article.outerheight()) {                     icon.css('top', article.outerheight())                 }                  if (!icon.hasclass('iconextend')) {                     icon.addclass('iconextend')                 }              }         }     }      if (iconclosed[0]) {          if (iconclosed.css('top') !== 0) {             iconclosed.css('top', 0)         }          if (iconclosed.hasclass('iconextend')) {             iconclosed.removeclass('iconextend')         }      } }  function raf() {      window.requestanimframe = (function () {         return window.requestanimationframe || window.webkitrequestanimationframe || window.mozrequestanimationframe || window.orequestanimationframe || window.msrequestanimationframe || function (callback) {             window.settimeout(callback, 1000 / 60);         };     })();      requestanimframe(raf);      accordionicon(); }  raf(); 

any appreciated.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -