Actively controlling the properties of localized optical modes is crucial for cavity quantum electrodynamics experiments. While several methods to tune the optical frequency have been demonstrated, the possibility of controlling the shape of the modes has scarcely been investigated. Yet an active manipulation of the mode pattern would allow direct control of the mode volume and the quality factor and therefore of the radiative processes. In this work, we propose and demonstrate a nano-optoelectromechanical device in which a mechanical displacement affects the spatial pattern of the electromagnetic field. The device is based on a double-membrane photonic crystal waveguide which, upon bending, creates a spatial modulation of the effective refractive index, resulting in an effective potential well or antiwell for the optical modes. The change in the field pattern drastically affects the optical losses: large modulations of the quality factors and dissipative coupling rates larger than 1 GHz/nm are predicted by calculations and confirmed by experiments. This concept opens new avenues in solid-state cavity quantum electrodynamics in which the field, instead of the frequency, is coupled to the mechanical motion.