Guest User

Untitled

a guest
Oct 3rd, 2015
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. /* Remove mascot class from element "main" if its width is <= mascotMinWidth */
  2. function controlMascot(mascot, mascotMinWidth) {
  3. $(window).resize(function(event) {
  4. if ( $(window).width() <= mascotMinWidth && $("main").hasClass("mascot") ) {
  5. removeMascot();
  6. } else if( $(window).width() > mascotMinWidth && ! $("main").hasClass("mascot") ) {
  7. setMascot(mascot);
  8. }
  9. });
  10. }
  11.  
  12. function setMascot(mascot) {
  13. $('main').addClass("mascot");
  14. $('main').css("background-image", "url(" + mascot + ")");
  15. $('main').removeClass("plain");
  16. }
  17.  
  18. function removeMascot() {
  19. $('main').removeClass("mascot");
  20. $('main').css("background-image", "");
  21. $('main').addClass("plain");
  22. }
  23.  
  24. $(document).ready(function(event) {
  25. var mascotEnable = true;
  26. var mascotPath = "images/mascots/"
  27. var mascotList = ['kurisu.png', 'kido.png', 'ruri3.png', 'ruri1.png', 'ruri2.png', 'ruri.png', 'nadeko.png', 'amakusa.png', 'hitagi.png', 'hitagi1.png', 'hitagi2.png', 'hitagi3.png', 'hitagi4.png', 'mio.png', 'nichijou.png', 'saber.png', 'Hanako.png', 'Kirino.png', 'Kuroneko.png', 'kurumu.png', 'misaka.png', 'yuno.png' ];
  28.  
  29. var mascot = mascotPath + mascotList[Math.floor(Math.random() * mascotList.length)];
  30. var mascotMinWidth = '750';
  31.  
  32. if ( mascotEnable ) {
  33. setMascot(mascot);
  34. controlMascot(mascot, mascotMinWidth);
  35. } else { removeMascot(); }
  36. });
Advertisement
Add Comment
Please, Sign In to add comment