Rather than rely upon Members opinions, put your dates into the EU Calculator and it will work out if the trip is permitted. A Forum Member is unlikely to be working as a Border Guard at your port when you arrive!
Enter the proposed entry date to the Schengen country and the proposed departure date to Morocco as the Leave Date. For your return trip, enter the Departure Date from Morocco as the Entry Date to the Schengen Zone, and enter the Leave or Deprture Date as the date that the ferry leaves France or Spain
Best not leave it too fine, though. We use Newhaven to Dieppe quite often and the ferry departure is sometimes 2359. A delay in clearing Customs could lose you a day, and yu don't want to be playing Cinderella!
Steve