jQuery window.scroll move div vertical in opposite direction

夙愿已清 提交于 2019-11-29 17:43:57

You can do:

{ top: -jQuery(window).scrollTop() + 'px' }

Also, a few tips to make it more efficient.

You're calling jQuery(window) and jQuery('.iphonepic') on every scroll event, that's really expensive. Just do:

var $window = jQuery(window), $iPhonePic = jQuery('.iphonepic')

$w.on('scroll', function(){

  var top = -$window.scrollTop();

  if ( top < -150 ) {
    top = -150;
  }

  $iPhonePic.stop().animate({
    top: top + 'px'
  }, "slow");
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!