Why is my male coworker hot and cold towards me?

First I should mention that there is absolutely no way we can date due to our circumstances. I have a boyfriend and plus workplace romances are strictly forbidden and I would never want to lose my job over this and I don't think he would either.

I am trying to figure out why this guy is my friend one minute and then the next minute acts like he doesn't even know me. This started when he walked into my office one day and I felt the weirdest "spark". It was literally like a spark - I never felt anything as odd as that before - ever. It happened when we made eye contact and it was so powerful that it nearly knocked me on my ***. It was really strong and it scared me because I didn't understand if he felt it too or if was just in my head. There were a few interesting things besides that: one time he looked me up and down and exclaimed how he loves how I can dress down on Fridays, another time he looked me up and down and said I had such cute little feet. I felt a lot of tension in the air between us those times - a lot. But then, he would not come near me for weeks (unless he absolutely had to) at all after things like that happened. We have the exact same sense of humor and always seem to have a great time when we are at work together. Our personalities are very similar and I can even finish some of the things he is going to say - we connect well, most of the time. I also caught him blatantly staring at me a few (not a lot) times. He used to come into my office to joke around, talk to my coworker and I - not all the time, but a lot. He always always shows pictures and videos of his child, even when the pictures are incredibly boring - it's like he is showing off or something. He would always joke with me a lot, fling rubber bands at me, push me (nicely, haha), tease me, etc. Then, in January, I was in his room (just me and him), and as we were talking, that spark thing happened again! Not as strong as the first time, but it happened. I went to leave the room because I felt so weirded out, but he kept changing the subject and initiating more conversation, as if to keep me in his room. Again, not sure if he felt it or if it was in my head. After that day, he was hanging around me a little more, offering to help me with projects without me asking him. He was offering to help me with things that had nothing to do with him. Every time we would talk, he would make very direct, intense eye contact (sort of made me uncomfortable). He then asked me a few different times to come to his room to do fun projects - paint stuff (I love to paint). He was working on a big project that had nothing to do with me and one day told me I could stay after work to help him with it (I wouldn't be getting paid to do that). I said I would help him, but the very next morning, he said he was just going to have the volunteers help him with the project so he didn't have to stay at work late. After he met my boyfriend he barely talks to me.