Fanfic is fine, like LostKelp is saying! Gotta be transparent about it, though.
What you're saying can be applied in a couple ways...
Retelling a fable or folklore or fairytale is totally fine! Especially since they're stories that are very old. If you retell Alice in Wonderland, it will be clear that it is a retelling of it because of the well known premise, themes, and character's purposes. Putting a twist on ye olden tales is fun.
You could even push it so far and it becomes less of what the original tale was, but remember that there are some people very into literary analysis and may even pick up your initial inspirations and link it back to stories they know that make good comparisons with yours.
Now... putting a twist on something like a show/movie/cartoon/book that is modern or current, this starts getting into blurry territory. Going this route, I'd highly encourage the deconstruction of the story that is inspiring you to make your own version of it--and I mean really break it down, make it better, add and subtract things. It becomes it's own thing, but not without an identifiable inspiration like I mentioned above.
Plagiarism would be copying an entire premise, character arc, copying lines and scenes, and keeping them all intact but just slapping different names/visuals on it. Pretty lame, even for fanfic. xD
Like, don't take a page from The Hobbit word-for-word and paste it into your story.
When you sell something like that, it's illegal and you can face repercussions.
Then there's the whole "parody" thing. lol
If you're online posting work to share for free with people, it doesn't really matter what you take story-wise from things (current or old), because you aren't trying to make a profit off of it. But your audience may have something to say about it, if you're trying to claim it as your own ideas.