Advertisement
Guest User

Untitled

a guest
Jul 17th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.04 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Application Home Page</title>
  6. <script src="https://code.jquery.com/jquery-1.10.2.js"></script>
  7. <style>
  8. .onoffswitch {
  9. position: relative; width: 90px;
  10. -webkit-user-select:none; -moz-user-select:none; -ms-user-select: none;
  11. }
  12. .onoffswitch-checkbox {
  13. display: none;
  14. }
  15. .onoffswitch-label {
  16. display: block; overflow: hidden; cursor: pointer;
  17. border: 2px solid #999999; border-radius: 20px;
  18. }
  19. .onoffswitch-inner {
  20. display: block; width: 200%; margin-left: -100%;
  21. transition: margin 0.3s ease-in 0s;
  22. }
  23. .onoffswitch-inner:before, .onoffswitch-inner:after {
  24. display: block; float: left; width: 50%; height: 30px; padding: 0; line-height: 30px;
  25. font-size: 14px; color: white; font-family: Trebuchet, Arial, sans-serif; font-weight: bold;
  26. box-sizing: border-box;
  27. }
  28. .onoffswitch-inner:before {
  29. content: "ON";
  30. padding-left: 10px;
  31. background-color: #FF7701; color: #FFFFFF;
  32. }
  33. .onoffswitch-inner:after {
  34. content: "OFF";
  35. padding-right: 10px;
  36. background-color: #EEEEEE; color: #999999;
  37. text-align: right;
  38. }
  39. .onoffswitch-switch {
  40. display: block; width: 18px; margin: 6px;
  41. background: #FFFFFF;
  42. position: absolute; top: 0; bottom: 0;
  43. right: 56px;
  44. border: 2px solid #999999; border-radius: 20px;
  45. transition: all 0.3s ease-in 0s;
  46. }
  47. .onoffswitch-checkbox:checked + .onoffswitch-label .onoffswitch-inner {
  48. margin-left: 0;
  49. }
  50. .onoffswitch-checkbox:checked + .onoffswitch-label .onoffswitch-switch {
  51. right: 0px;
  52. }
  53. </style>
  54. </head>
  55. <body>
  56. <div class="onoffswitch">
  57. <input type="checkbox" name="onoffswitch" class="onoffswitch-checkbox" id="myonoffswitch" checked>
  58. <label class="onoffswitch-label" for="myonoffswitch">
  59. <span class="onoffswitch-inner"></span>
  60. <span class="onoffswitch-switch"></span>
  61. </label>
  62. </div>
  63. <script>
  64. $('input[name=onoffswitch]').change(function(){
  65. if($(this).is(':checked')) {
  66. handleAJAXRequest('on');
  67. } else {
  68. handleAJAXRequest('off')
  69. }
  70. });
  71. function handleAJAXRequest(key){
  72. url = "switch"+key;
  73. var xmlHttpReq = new XMLHttpRequest();
  74. xmlHttpReq.open("GET", url, true);
  75. xmlHttpReq.send(null);
  76. xmlHttpReq.onreadystatechange = function() {
  77. if (xmlHttpReq.readyState === 4) {
  78. console.log(xmlHttpReq.responseText);
  79. if (xmlHttpReq.status === 200) {
  80. console.log('successful');
  81. } else {
  82. console.log('failed');
  83. }
  84. }
  85. }
  86. }
  87. </script>
  88. </body>
  89. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement