Upvote:1
To answer this question explicitly - yes you can. I successfully did the same thing but for Italy -> Romania (as opposed to Spain -> Croatia).
Upvote:2
We have a lot of related questions but I don't think we have one covering this particular situation. Basically, your type D visa is equivalent to a residence permit in the Schengen area.
It can also be used to visit Romania, Bulgaria and Croatia. From the Croatian Ministry of Foreign and European Affairs:
Aliens who are holders of:
[…] long-stay visa (D) for stays exceeding three months, issued by one of the Schengen Area Member State; […]
do not require a visa for transit or intended stays in the territory of Croatia not exceeding 90 days in any 180-day period.