jQuery banner 滑动

jQuery(document).ready(function() {
var abovePos = 50;
var customMax = 1600;
var zIdx = 100;
var $bnr = $('#block');
var $win = $(window);
var $doc = $(document);

$bnr.css('zIndex', zIdx);

var offset = $bnr.offset();
var pos = $bnr.position();
var maxPos = customMax - abovePos;

$win.scroll(function() {
  var st = $doc.scrollTop();
  var newPos = st - offset.top;
  if (st > offset.top) {
    if (st > maxPos) {
      newPos = maxPos - offset.top;
    }
    $bnr.stop().animate({
      top: pos.top + newPos + abovePos
    });
  } else {
    $bnr.stop().animate({
      top: pos.top
    })
  }
});
});

在线DEMO: http://output.jsbin.com/mogufewodu

posted @ 2016-04-13 17:02  roseforyou  阅读(231)  评论(0编辑  收藏  举报