Online - Offline Simulator

Developer
Size
2,407 Kb
Views
6,072

How do I make an online - offline simulator?

What is a online - offline simulator? How do you make a online - offline simulator? This script and codes were developed by Robert on 09 January 2023, Monday.

Online - Offline Simulator Previews

Online - Offline Simulator - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Online - Offline Simulator</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="css/style.css">
</head>
<body> <html ng-app="myApp">
<head> <script src="https://code.jquery.com/jquery-1.9.1.min.js"></script> <script src="https://code.angularjs.org/1.0.5/angular.min.js"></script>
</head>
<body ng-controller="Ctrl"> <div class="offline" ng-class="{'online' : online}"> </div>
</body>
</html> <script src="js/index.js"></script>
</body>
</html>

Online - Offline Simulator - Script Codes CSS Codes

.offline { background-color: lightgray; width: 16px; height: 16px; border-radius: 50%;
}
.online { background-color: green;
}

Online - Offline Simulator - Script Codes JS Codes

 // Outside of Angular window.myVar = {online: true, cachedItems: []}; var myVarWatch = (function() { var watches = {}; return { watch: function(callback) { var id = Math.random().toString(); watches[id] = callback; // Return a function that removes the listener return function() { watches[id] = null; delete watches[id]; } }, trigger: function() { for (var k in watches) { watches[k](window.myVar); } } } })(); function callTimer(){ setTimeout(function() { window.myVar.online = Math.floor(Math.random()*2) === 0 ? false : true; myVarWatch.trigger(); callTimer(); }, 2000); } callTimer(); // Inside of Angular angular.module('myApp', []).controller('Ctrl', function($scope) { $scope.online = true; var unbind = myVarWatch.watch(function(newVal) { $scope.online = newVal.online; $scope.$apply(); //console.log("ONLINE:", $scope.online); }); // Unbind the listener when the scope is destroyed $scope.$on('$destroy', unbind); });
Online - Offline Simulator - Script Codes
Online - Offline Simulator - Script Codes
Home Page Home
Developer Robert
Username AgentRR007
Uploaded January 09, 2023
Rating 3
Size 2,407 Kb
Views 6,072
Do you need developer help for Online - Offline Simulator?

Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!

Robert (AgentRR007) Script Codes
Create amazing video scripts with AI!

Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!