Skip to main content

best solution for alternating an image and div

Comments

3 comments

  • VISUI

    if the toggle isn't meant to refresh any data or content from the server, I prefer to use jQuery to control the logic.  This keeps everything browser-side and jQuery provides very simple methods.

    <Report ID="LogiForum.Toggle">
      <IncludeScriptFile IncludedScriptFile="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js" />
      <Body>
        <Image Caption="https://cdn3.iconfinder.com/data/icons/faticons/32/arrow-up-01-512.png" Height="30" ID="imgToggle">
          <Action Type="Javascript" Javascript="var imgsrc1 = 'https://cdn3.iconfinder.com/data/icons/faticons/32/arrow-up-01-512.png';&#xD;&#xA;var imgsrc2 = 'https://cdn3.iconfinder.com/data/icons/faticons/32/arrow-down-01-512.png';&#xD;&#xA;&#xD;&#xA;if ($('#imgToggle').attr('src') == imgsrc1) {&#xD;&#xA;    $('#imgToggle').attr('src',imgsrc2);&#xD;&#xA;    $('#div1').hide();&#xD;&#xA;    $('#div2').fadeIn();&#xD;&#xA;}&#xD;&#xA;else {&#xD;&#xA;    $('#imgToggle').attr('src',imgsrc1);&#xD;&#xA;    $('#div2').hide();&#xD;&#xA;    $('#div1').fadeIn();&#xD;&#xA;}" />
        </Image>
        <Division ID="div1" HtmlDiv="True">
          <Label Caption="Division 1" Class="h1" />
        </Division>
        <Division ID="div2" HtmlDiv="True" ShowModes="None">
          <Label Caption="Division 2" Class="h1" />
        </Division>
      </Body>
    </Report>

    Here is the jQuery used:


    var imgsrc1 = 'https://cdn3.iconfinder.com/data/icons/faticons/32/arrow-up-01-512.png';
    var imgsrc2 = 'https://cdn3.iconfinder.com/data/icons/faticons/32/arrow-down-01-512.png';

    if ($('#imgToggle').attr('src') == imgsrc1) {
        $('#imgToggle').attr('src',imgsrc2);
        $('#div1').hide();
        $('#div2').fadeIn();
    }
    else {
        $('#imgToggle').attr('src',imgsrc1);
        $('#div2').hide();
        $('#div1').fadeIn();
    }

     

     

    0
  • VISUI

    For a Logi Only version using Showmodes and ActionShowElement...

     

    <Report ID="LogiForum.Toggle2">
      <Body>
        <Division ID="img1">
          <Image Caption="https://cdn3.iconfinder.com/data/icons/faticons/32/arrow-up-01-512.png" Height="30" ID="imgToggle1">
            <Action Type="ShowElement" Display="Toggle" ElementID="img2,div2,img1,div1" ID="ase2" />
          </Image>
        </Division>
        <Division ID="img2" ShowModes="None">
          <Image Caption="https://cdn3.iconfinder.com/data/icons/faticons/32/arrow-down-01-512.png" Height="30" ID="imgToggle2">
            <Action Type="ShowElement" Display="Toggle" ElementID="img2,div2,img1,div1" ID="ase2" />
          </Image>
        </Division>
        <Division HtmlDiv="True" ID="div1">
          <Label Caption="Division 1" Class="h1" />
        </Division>
        <Division HtmlDiv="True" ID="div2" ShowModes="None">
          <Label Caption="Division 2" Class="h1" />
        </Division>
      </Body>
    </Report>
    0
  • Scott Florcsk

    Thank you for the code. I implemented your second solution and it worked perfectly!

    0

Please sign in to leave a comment.