滚动时留下Javascript边距

时间:2016-07-26 11:08:15

标签: javascript jquery html css

我希望剩余边距在某一点停止

var data = $('#nexttologodiv').css('margin-left');
var init = 220, 
    $page = $('#nexttologodiv').css('margin-left', init);

console.log(data);

window.onscroll = function() {
  if (data == '220px'){
    $page.removeClass( 'scrolled' );
    console.log(window.scrollY);
    $page.css('margin-left', init - window.scrollY * 2);
  }
  else if (window.scrollY <= 48) {
    $page.css('margin-left', 0 - window.scrollY);
  }}
}

0 个答案:

没有答案