Logic Machine Forum
Backround image change - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Visualization (https://forum.logicmachine.net/forumdisplay.php?fid=9)
+--- Thread: Backround image change (/showthread.php?tid=5555)



Backround image change - 2MAX - 07.08.2024

Hi, is it possible to change background image of room if one or more lights are switch to on?


RE: Backround image change - admin - 28.08.2024

Here's a working example that should be added to Custom JavaScript. Change tag, plan_id and img variables as needed.
Code:
$(function() {
  if (typeof grp != 'object') {
    return;
  }

  var tag = 'light';
  var plan_id = 1;

  function check() {
    var objs = grp.tag(tag);
    var res = false;
    
    $.each(objs, function(id, obj) {
      res = res || obj.value;
    });

    if (currentPlanId == plan_id) {
      var img;

      if (res) {
        img = '/scada/resources/img/light.png';
      }
      else {
        img = '/scada/resources/img/dark.png';
      }

      img = 'url(' + img + ')';

      $E.planBg
        .css('background-image', img)
        .data('background-image', img);
    }
  }

  grp.taglisten(tag, check);
  $E.body.on('showplan', check);
});