0

如何在此代码中添加一个子句,在每次调整大小之前将先前的宽度保存到变量中?

 $(window).on('load resize', function() {           
      var w = $(window).width();
      var h = $(window).height();

      $('#right1').css('top' , w > 1250 ? -120 : -73 );  

    });
4

1 回答 1

1
var oldW = $(window).width();
var oldH = $(window).height();

$(window).on('load resize', function () {
  var w = $(window).width();
  var h = $(window).height();

  $('#right1').css('top', w > 1250 ? -120 : -73);

  //Finish what you want with oldH and oldW.... 
  oldH = h;
  oldW = w;
});
于 2013-01-09T22:19:38.817 回答