Optical trapping is a powerful manipulation and measurement technique widely used in the biological and materials sciences. Miniaturizing optical trap instruments onto optofluidic platforms holds promise for high-throughput lab-on-a-chip applications. However, a persistent challenge with existing optofluidic devices has been achieving controlled and precise manipulation of trapped particles. Here, we report a new class of on-chip optical trapping devices. Using photonic interference functionalities, an array of stable, three-dimensional on-chip optical traps is formed at the antinodes of a standing-wave evanescent field on a nanophotonic waveguide. By employing the thermo-optic effect via integrated electric microheaters, the traps can be repositioned at high speed (∼30 kHz) with nanometre precision. We demonstrate sorting and manipulation of individual DNA molecules. In conjunction with laminar flows and fluorescence, we also show precise control of the chemical environment of a sample with simultaneous monitoring. Such a controllable trapping device has the potential to achieve high-throughput precision measurements on chip.