javascript - CSS - 触摸屏放大时更改背景网址

标签 javascript jquery html css

我正在使用触摸屏工作,在此屏幕 (1920 x 1080) 上,用户可以使用手指进行平移和缩放。

在此屏幕上,我正在显示平面图。这一直是一场噩梦,让它们在不放大和放大时看起来不模糊....这是我的 css 代码,图像在不放大时看起来不错

.blackline {
    text-align: center;
    position: absolute;
    top: 375px;
    height: 850px;
    width: 1058px;
    background: url('/images/floorplans/test-2.png') top center;
    background-size: contain;
    background-repeat: no-repeat;
    background-color: #FFF;
}

<div class="blackline"></div>

我有另一个名为 test.png 的图像,在触摸屏上放大时看起来不错。

我的问题是,我是否可以在放大时使用 css、html、javascript 或 jquery 更改背景图像,并在不放大时将其改回原样?这可能吗?

最佳答案

最好考虑 SVG 图像,因为在缩放时不会扭曲自身(即使更改缩放也不必更改它)。

另一种方法是通过 JQuery 根据缩放级别更改背景图像:

var zoom = document.documentElement.clientWidth / window.innerWidth;
$(window).resize(function() {
    var zoomNew = document.documentElement.clientWidth / window.innerWidth;
    if (zoom != zoomNew) {
        // zoom has changed
        // change the background image accordingly
        //and set new zoom as current zoom
        zoom = zoomNew
    }
});

关于javascript - CSS - 触摸屏放大时更改背景网址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57958674/

相关文章:

php - 使用 Facebook 应用程序对网络链接进行一次性身份验证

javascript - 使用 javascript 从 HTML 转换为文本时出现问题

javascript - 淡入 JQuery 不起作用?

html - 如何修复溢出其容器的图像?

javascript - scrollTop 与 getBoundingClientRect().top

javascript - 为什么我的 for 循环弄乱了所有参数?

javascript - 如何在 Javascript 中动态获取 JSON 数组名称

javascript - Js标准对象(以字符串为键的数组)作为ajax发布数据不起作用

javascript - 如何使用 Ajax 和 footable_redraw 将新行填充到 Footable

html - 为什么我的 bootstrap 列表现异常?