We explore the evolution of cooperation in a public goods game where the habitat destruction is taken into account. A model of ordinary differential equations is proposed, in which incorporate the habitat destroyed. And we focus on the impact of different levels of habitat destruction on cooperation. Our results show that the fraction of cooperation receives the biggest boost for moderate habitat destruction, and decreases to zero very quickly for a higher degree of habitat destruction. Similarly, our results suggest that low or moderate habitat degradation can promote the evolution of cooperators, and once habitat degradation is too severe, the fraction of cooperators will decline dramatically. Furthermore, we investigate the cooperation level with different multiplication factor, and results demonstrate that the cooperation increases monotonously with the increasing of the multiplication factor. Our findings may provide many more insights for understanding the emergence and maintenance of cooperation in the complex biological and social systems.