Fight fire with water.
Say to your kids:
"Your Dad loves you but he is not acting nicely. It's not nice to turn children against parents or parents against children. That is not correct behaviour, especially for an adult and Dad may not realize this. I don't want to say bad things about your dad and if he says stuff to you about me that is not nice, please don't believe it and please remember how much I love you and how much I want you to live with me. I really do love you very much. I love this and this and this about you and I will never stop loving you and wanting to be near you, and close to you."
Make a list of all the reasons why they are better off living with you. Mention them casually along with expressions of your love for them. Never mind debating the junk he's spewing to them about you. Spew love and kindness and good words to them and encourage them in every possible way, about themselves and about their good behaviour.
If they misbehave, tell them you know everything must be very confusing for them. Encourage them to talk about their feelings and their desires. Acknowledge their feelings and help them to feel as if they can talk with you about anything. Comfort their worries. Try to do something fun, as often as possible. A game of cards? Something active that they like? Build good memories often with them!!
Communication is the key that will keep the door to your heart open with them. Release your negative feelings in appropriate ways (a journal is good) and try your hardest to be patient, kind and loving while around your kids. They will pick up on his negativity and soon, they will want to be with you more than that negative environment. They are only children and they can't be expected to understand all this. Encourage them to express what's bothering them and encourage and love them in return.
Best of luck. No giving up. You can be just as nice as he is not! Which would you prefer, if you were a kid?