jQuery - Execute scripts based on screen size

前端 未结 4 1478

Is it possible to only run certain jQuery scripts if the screen/device size is above xxx pixels wide?

So, for example, I only want to run a slideshow when people are

4条回答
  •  半阙折子戏
    2020-12-04 15:14

    You might also consider a library like https://github.com/paulirish/matchMedia.js/

    if (matchMedia('only screen and (max-width: 480px)').matches) {
      // smartphone/iphone... maybe run some small-screen related dom scripting?
    }
    

提交回复
热议问题