2016年6月22日 星期三

【Jquery】position:fixed 可左右拉動

今天遇到一件奇怪的需求,

在使用 CSS position:fixed 使區塊固定時,

當拉動左右的卷軸時這個區塊也要跟著動,

這時只能用javascript來解決:

$(window).scroll(function(){
  $(".nav").css({ // 要移動的class或div
    'left': 0 - $(this).scrollLeft()
  });
  $(".footer").css({
    'left': 0 - $(this).scrollLeft()
  });
});