$(function() { var $window = $(window), $aside = $('#move_window'), defaultPositionLeft = $aside.css('left'), setOffsetPosition = $aside.offset(), fixedClassName = 'fixed', contentWidth = $('.applyContents').innerWidth(); var fixPosition = function(){ var w = (window.innerWidth + contentWidth)/2 - 102; if (window.innerWidth <= contentWidth){ w = 'calc(100% - 94px)'; } return w; } $window.on('scroll resize', function() { $aside.addClass(fixedClassName).css('left', fixPosition); }); $window.trigger('scroll'); });