Mediation analysis is a valuable approach to examine pathways in epidemiological research. Prospective cohort studies are often conducted to study biological mechanisms and often collect longitudinal measurements on each participant. Mediation formulae for longitudinal data have been developed. Here, we formalize the natural direct and indirect effects using a causal framework with potential outcomes that allows for an interaction between the exposure and the mediator. To allow different types of longitudinal measures of the mediator and outcome, we assume two generalized mixed-effects models for both the mediator and the outcome. The model for the mediator has subject-specific random intercepts and random exposure slopes for each cluster, and the outcome model has random intercepts and random slopes for the exposure, the mediator, and their interaction. We also expand our approach to settings with multiple mediators and derive the mediated effects, jointly through all mediators. Our method requires the absence of time-varying confounding with respect to the exposure and the mediator. This assumption is achieved in settings with exogenous exposure and mediator, especially when exposure and mediator are not affected by variables measured at earlier time points. We apply the methodology to data from the Normative Aging Study and estimate the direct and indirect effects, via DNA methylation, of air pollution, and temperature on intercellular adhesion molecule 1 (ICAM-1) protein levels. Our results suggest that air pollution and temperature have a direct effect on ICAM-1 protein levels (i.e. not through a change in ICAM-1 DNA methylation) and that temperature has an indirect effect via a change in ICAM-1 DNA methylation.