gpt4 book ai didi

javascript - 如何在鼠标悬停时的弹出窗口中显示放大的图像,或者在 RShiny 的 rhandsontable 单元格中显示的图像上的单击事件上显示放大的图像?

转载 作者:行者123 更新时间:2023-12-05 00:38:49 30 4
gpt4 key购买 nike

我想在鼠标悬停或单击事件上显示一个放大的弹出图像,该图像显示在 rhandsontable 单元格中,类似于所示 here在 DT 表中。
enter image description here
我想显示在创建的表中显示的图像的弹出图像,如下所示:

library(rhandsontable)

DF = data.frame(
comments = c(
"I would rate it ★★★★☆",
"This is the book about JavaScript"
),
cover = c(
"http://ecx.images-amazon.com/images/I/51bRhyVTVGL._SL50_.jpg",
"http://ecx.images-amazon.com/images/I/51gdVAEfPUL._SL50_.jpg",
),
stringsAsFactors = FALSE
)

rhandsontable(DF, allowedTags = "<em><b><strong><a><big>",
width = 800, height = 450, rowHeaders = FALSE) %>%
hot_cols(colWidths = c(200, 80)) %>%
hot_col(1, renderer = htmlwidgets::JS("safeHtmlRenderer")) %>%
hot_col(2, renderer = "
function(instance, td, row, col, prop, value, cellProperties) {
var escaped = Handsontable.helper.stringify(value),
img;

if (escaped.indexOf('http') === 0) {
img = document.createElement('IMG');
img.src = value; img.style.width = '80px'; img.style.height = '80px';

Handsontable.dom.addEvent(img, 'mousedown', function (e){
e.preventDefault(); // prevent selection quirk
});

Handsontable.dom.empty(td);
td.appendChild(img);
}
else {
// render as text
Handsontable.renderers.TextRenderer.apply(this, arguments);
}

return td;
}")

最佳答案

这是 solution这将在视口(viewport) - 浏览器窗口中居中元素(图像或图形)点击事件。
请注意小的更改(为了更好的图像显示):_SL500_.jpgimg.style.width = 'auto'; .

library(magrittr)
library(htmlwidgets)
library(rhandsontable)

DF = data.frame(
comments = c(
"I would rate it &#x2605;&#x2605;&#x2605;&#x2605;&#x2606;",
"This is the book about JavaScript"
),
cover = c(
"http://ecx.images-amazon.com/images/I/51bRhyVTVGL._SL500_.jpg",
"http://ecx.images-amazon.com/images/I/51gdVAEfPUL._SL500_.jpg"
),
stringsAsFactors = FALSE
)

rhandsontable::rhandsontable(DF, allowedTags = "<em><b><strong><a><big>",
callback = htmlwidgets::JS(

"$(document).ready(function() {
$('body').prepend('<div class=\"zoomDiv\"><img src=\"\" class=\"zoomImg\"></div>');
// onClick function for all plots (img's)
$('img:not(.zoomImg)').click(function() {
$('.zoomImg').attr('src', $(this).attr('src')).css({width: '100%'});
$('.zoomDiv').css({opacity: '1', width: 'auto', border: '1px solid white', borderRadius: '5px', position: 'fixed', top: '50%', left: '50%', marginRight: '-50%', transform: 'translate(-50%, -50%)', boxShadow: '0px 0px 50px #888888', zIndex: '50', overflow: 'auto', maxHeight: '100%'});
});
// onClick function for zoomImg
$('img.zoomImg').click(function() {
$('.zoomDiv').css({opacity: '0', width: '0%'});
});
});"

),
width = 800, height = 450, rowHeaders = FALSE) %>%
hot_cols(colWidths = c(200, 80)) %>%
hot_col(1, renderer = htmlwidgets::JS("safeHtmlRenderer")) %>%
hot_col(2, renderer = "
function(instance, td, row, col, prop, value, cellProperties) {
var escaped = Handsontable.helper.stringify(value),
img;

if (escaped.indexOf('http') === 0) {
img = document.createElement('IMG');
img.src = value; img.style.width = 'auto'; img.style.height = '80px';

Handsontable.dom.addEvent(img, 'mousedown', function (e){
e.preventDefault(); // prevent selection quirk
});

Handsontable.dom.empty(td);
td.appendChild(img);
}
else {
// render as text
Handsontable.renderers.TextRenderer.apply(this, arguments);
}

return td;
}")

输出:
enter image description here

关于javascript - 如何在鼠标悬停时的弹出窗口中显示放大的图像,或者在 RShiny 的 rhandsontable 单元格中显示的图像上的单击事件上显示放大的图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71189131/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com