jquery在调整大小之前保存宽度

时间:2013-01-09 22:16:38

标签: jquery

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

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

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

    });

1 个答案:

答案 0 :(得分: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;
});