Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Kevp 8 posts 98 karma points
    Jun 03, 2020 @ 18:29
    Kevp
    0

    Simple unique id for div

    Hi,

    New to umbraco, razor and c.

    I need a unique id on each instance of my partial and the included parallax script. This way the script only starts the effect when reaching the bounds of that specific element. Is there built-in functionality in umbraco that could help me out ?

    The result should look like this, in short, where the -165160 is generated, yet the same for script and div.

    <div class="infoblock-165160">
    ...
    </div>
    
    <script>
        var rellax = new Rellax('.rellaximage', {
        wrapper: 'infoblock-165160';
    ...
    }
    </script>
    

    Grts,

  • Tobias Klika 101 posts 570 karma points c-trib
    Jun 03, 2020 @ 18:44
    Tobias Klika
    100
    @{
        // take the first block of a GUID
        string id = Guid.NewGuid().ToString().Split('-')[0];    
    }
    <div class="infoblock-@id">
    ...
    </div>
    
    <script>
        var rellax = new Rellax('.rellaximage', {
        wrapper: 'infoblock-@id';
    ...
    }
    </script>
    
  • Kevp 8 posts 98 karma points
    Jun 05, 2020 @ 11:35
    Kevp
    0

    Hi Tobias,

    Thanks a lot for your reply and the insight! Works like a charm!

    Grts,

Please Sign in or register to post replies

Write your reply to:

Draft