At the time it was believed that the things a person or animal is thinking about at the moment of conception could effect the appearance of the child. See Seforno to Genesis 30:38. This is called "maternal imprinting." This belief was very common in the ancient world and still prevalent in Talmudic times. See this article on the subject from Talmudology.
However, in the next chapter in Genesis (31:10-12) it is revealed to Jacob prophetically that it was not his attempts at maternal imprinting that succeeded in causing the birth of the spotted and speckled sheep but rather Divine intervention:
וַיְהִ֗י בְּעֵת֙ יַחֵ֣ם הַצֹּ֔אן וָאֶשָּׂ֥א עֵינַ֛י וָאֵ֖רֶא בַּחֲל֑וֹם וְהִנֵּ֤ה הָֽעַתֻּדִים֙ הָעֹלִ֣ים עַל־הַצֹּ֔אן עֲקֻדִּ֥ים
נְקֻדִּ֖ים וּבְרֻדִּֽים׃
“Once, at the mating time of the flocks, I had a dream in which I saw
that the he-goats mating with the flock were streaked, speckled, and
mottled.
וַיֹּ֨אמֶר אֵלַ֜י מַלְאַ֧ךְ הָאֱלֹהִ֛ים בַּחֲל֖וֹם יַֽעֲקֹ֑ב
וָאֹמַ֖ר הִנֵּֽנִי׃
And in the dream an angel of God said to me, ‘Jacob!’ ‘Here,’ I
answered.
וַיֹּ֗אמֶר שָׂא־נָ֨א עֵינֶ֤יךָ וּרְאֵה֙ כָּל־הָֽעַתֻּדִים֙
הָעֹלִ֣ים עַל־הַצֹּ֔אן עֲקֻדִּ֥ים נְקֻדִּ֖ים וּבְרֻדִּ֑ים כִּ֣י
רָאִ֔יתִי אֵ֛ת כָּל־אֲשֶׁ֥ר לָבָ֖ן עֹ֥שֶׂה לָּֽךְ׃
And he said, ‘Note well that all the he-goats which are mating with
the flock are streaked, speckled, and mottled; for I have noted all
that Laban has been doing to you.
And Rashi on Genesis 31:10 quotes the Midrash that although Laban had separated the colored sheep from the flock, angels were transporting them to Jacob's flock to mate with the female sheep.
Thus, it appears from the simple meaning of the verses that Jacob attempted to use maternal imprinting as a technique to get his wages. But in reality it was not the maternal imprinting that was successful but a miracle.