简体   繁体   English

Django 管理员 - 在 hover 上显示图像

[英]Django Admin - display image on hover

I'd like to display a thumbnail in a popover when I hover over text (a camera emoji) in our Django Admin view.当我在 Django 管理视图中的文本(相机表情符号)上 hover 时,我想在弹出窗口中显示缩略图。 The code I have works, but displays the image inline, which disrupts the rest of the layout of the site我的代码有效,但内联显示图像,这破坏了站点布局的 rest

I'm by no means a Django expert, so there might be something easy I'm missing.我绝不是 Django 专家,所以我可能缺少一些简单的东西。 I'm totally open to using other libraries to help if that's the best path forward, but am not sure of how to appropriately load them in to django admin.如果这是最好的前进道路,我完全愿意使用其他库来提供帮助,但我不确定如何将它们适当地加载到 django 管理员中。 I'm also open to pure js/css solutions - whatever works best!我也对纯 js/css 解决方案持开放态度——无论哪种效果最好!

Here's the code that I have这是我的代码

def image_column(self, obj):
    format_html(foo + " " + \
            '''<a href="{}"" target="_blank" 
            style="font-size: 18pt" 
            onmouseover="document.getElementById('{}_img').style.display='block';"
            onmouseout="document.getElementById('{}_img').style.display='none';">📷  
            <img id="{}_img" style="display:none" src="{}" />'''.format(img_url, img_id, img_id, img_id, img_url)

I'd love any thoughts or suggestions on the best way to make it 'popover' instead of display inline.我喜欢任何关于使其“弹出”而不是内联显示的最佳方式的想法或建议。 Thank you!!谢谢!!

EDIT: Things are working now, with the exception of the camera emoji displaying over the pop over.编辑:现在一切正常,除了弹出窗口上显示的相机表情符号。 The image in the background is a map (which should be on top).背景中的图像是 map(应该在顶部)。 The camera image is from the row beneath it相机图像来自其下方的行

弹出上方的相机表情符号

That might only be an issue to do with the position property of the image, if it is position: relative , then it will fix itself among the other elements, you have to set it to position: absolute and from here you should give it top and left , for example: top: 0px; left: 0px;这可能仅与图像的 position 属性有关,如果它是top position: relative ,那么它将在其他元素中自行修复,您必须将其设置为position: absoluteleft ,例如: top: 0px; left: 0px; top: 0px; left: 0px; relative to the parent element which I guess is the <a> element... And you should also apply position: relative to the parent element: which again I think is <a> or whichever parent element is to the <img> element相对于我猜是<a>元素的父元素...而且您还应该应用position: relative对于父元素:我再次认为是<a>或任何父元素是<img>元素

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM