I don't think that there is any one answer to this.
However:
1) according to Shadal, indeed, the koach hadimyon (imaginative faculties) were at work in causing the coloring of the sheep.
By power of the imagination, just as it is well known that the imaginative faculties work for females and causes them to give birth to that which is imprinted forcefully upon their imagination. And see Bourdach in his work Physiologie (Leipzig, 1837), who brings many cases which were in this generation, which prove conclusively that the imaginative force works upon the fetus, not only at the time of conception, but also before the conception.
2) At the same time, he presents an alternate explanation by which the female sheep preferred male sheep which matched the pattern of the sticks.
Rather, his intent was that when those sticks would be in sight of the sheep at the time that they went into heat, and their souls {/desire} would attach to things similar, and when they went to pair with a male, they would attach to those males whose appearance was similar to the appearance of the sticks.
He connects it with an idea put forth in Bereishit Rabba, though I am not convinced that that is the intent of that midrash.
3) I also present in the above link the opinion of Dr. Yehuda Feliks, that Yaakov Avinu knew modern genetics, before Gregor Mendel did. And thus, a way it can work in accordance with modern genetics. I don't find this last one entirely convincing.
4) Finally, my own position (with grounding in ideas by R' Yosef Ibn Caspi in general) is that Yaakov Avinu thought that he was accomplishing something, based on contemporary science. Of course, contemporary science was bunk. However, “Rabbos machshavos b'lev ish, va'atzas Hashem, hi takum.” And indeed, according to Yaakov's dream, it was Divine Intervention which caused this. Still, Yaakov did his hishtadlus, which was understood (by him and others) to be genuine hishtadlus based on the mistaken beliefs of the time.
Edit: I'll just add that HodOfHod's answer is legitimate, in that this presents the view of Chazal. They believed, based on contemporary science, that the imaginative faculties would have an impact on the fetus. And the story cited to bolster this is a indeed a maaseh shehaya. But in that maaseh shehaya, there was most likely indeed infidelity, and Rebbe resolved it incorrectly as maternal impression. See here for a contemporary parallel.