XF 2.1 How to reduce the opacity of an image thumbnail (attachment)?

attachment_macros

Code:
                    <img src="{$attachment.thumbnail_url}" alt="{$attachment.filename}" />

How do I add opacity attribute to this img tag?

I tried:

Code:
<style>div.fade {opacity:0.6;}</style>
<img src="{$attachment.thumbnail_url}" alt="{$attachment.filename}" class="fade" />

It doesn't work.
 
Quite simple.. ;)
Add the following code to your extra.less:
Less:
.bbImage {
    opacity: .5;
   
    &:hover {
        opacity: 1;
    }
}
.attachment-icon {
    &.attachment-icon--img {
        img {
            opacity: .5;
           
            &:hover {
                opacity: 1;
            }
        }
    }
}

2020-04-24_20-52-21 (1).gif

2020-04-24_21-05-54 (1).gif
 
Last edited:
Not that easy. You should add additional classes per TMS and set conditional statements per TMS like..
Code:
<xf:if is="{{$xf.visitor.isMemberOf([x, y])}}">
    Show content...
</xf:if>
 
Create two TMS for your needs.
Template: attachment_macros
Modification key: AddFadeToImg
Find:
Code:
<img src="{$attachment.thumbnail_url}" alt="{$attachment.filename}" />
Replace:
Code:
<xf:if is="{{$xf.visitor.isMemberOf([3, 4])}}">
    <img class="fade" src="{$attachment.thumbnail_url}" alt="{$attachment.filename}" />
<xf:else />
    $0
</xf:if>

Template: lightbox_macros
Modification key: AddFadeToImgAttach
Find:
Code:
<img src="{$src}" data-url="{$dataUrl}" class="bbImage" data-zoom-target="1" {{ $alt ? 'alt="' . $alt|for_attr . '"' : '' }} style="{$styleAttr}" />
Replace:
Code:
<xf:if is="{{$xf.visitor.isMemberOf([3, 4])}}">
    <img src="{$src}" data-url="{$dataUrl}" class="bbImage fade" data-zoom-target="1" {{ $alt ? 'alt="' . $alt|for_attr . '"' : '' }} style="{$styleAttr}" />
<xf:else />
    $0
</xf:if>

Replace the extra.less entry with the following:
Less:
.fade {
    opacity: .5;
  
    &:hover {
        opacity: 1;
    }
}

The numbers 3, 4 in <xf:if is="{{$xf.visitor.isMemberOf([3, 4])}}"> are the usergroup IDs
 

Attachments

  • 2020-04-24_21-29-54.webp
    2020-04-24_21-29-54.webp
    64 KB · Views: 2
  • 2020-04-24_21-30-48.webp
    2020-04-24_21-30-48.webp
    60.1 KB · Views: 2
Please comment on my way of modification:

template: bb_code_tag_attach

find:
Code:
<img src="{$attachment.thumbnail_url}"
        class="bbImage {$alignClass}"
        style="{$styleAttr}"
        alt="{$alt}" />

replace:
Code:
<xf:if is="{{$xf.visitor.isMemberOf([1, 4])}}">
<style>
    .bbImage {
    opacity: .1;
}
</style>
</xf:if>
$0

see if I'm missing anything or whether it's not a good style of doing so..
 
Got it.

I got to that dirty method (yeah I felt something wrong with it too so I asked for your comment) before seeing your helpful solution.

I learned a lot from you guys! Thanks.
 
Back
Top Bottom