javascript - 简单的 jQuery 图像缩放 - 溢出超大浏览器窗口

标签 javascript jquery html css

我整理了我正在处理的一个小图像缩放脚本的这个简化版本。

https://jsfiddle.net/cvanderlinden/jjrhgxvv/4/

HTML:

<div class="image-zoom">
  <div class="zoom--actions">
    <a href="#" class="zoom-in">Zoom In</a>
    <a href="#" class="zoom-out">Zoom In</a>
  </div>
  <div class="zoom--img">
    <img src="https://www.google.ca/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png">
  </div>
</div>

JS(jQuery):

$('.zoom--actions .zoom-in').on('click', function () {
        var img = $(this).parents('.image-zoom').find('.zoom--img img');
        var width = img.width();
        var newWidth = width + 100;
        img.width(newWidth);
    }
);
$('.zoom--actions .zoom-out').on('click', function () {
        var img = $(this).parents('.image-zoom').find('.zoom--img img');
        var width = img.width();
        var newWidth = width - 100;
        img.width(newWidth);
    }
);

它按预期工作,我发现的唯一问题是,它似乎只想缩放直到达到窗口宽度,然后停止。它在 jsfiddle 上似乎无关紧要,但在真正的浏览器中,它停止了。如何让图像超过浏览器窗口宽度,并隐藏滚动,让溢出发生。

最佳答案

似乎某些css规则限制了图像放大。 如果添加样式:

img { max-width: 100%; }

你的 fiddle ,你会得到同样的效果。 所以你需要检查你的样式表是否存在类似的规则。 这是一个 fiddle 演示 issue

关于javascript - 简单的 jQuery 图像缩放 - 溢出超大浏览器窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42308371/

相关文章:

javascript - 用razor添加js代码

javascript - onclick 功能在 safari 中不起作用

javascript - 当 Assets 的 URL 具有可变查询参数时如何缓存 Assets ?

jquery - asp.net MVC 3 分页哪个最好用

php - 单击提交按钮时,保留并传递在 javascript 中创建的动态生成的 html 表到 php

python - 阅读 html 格式的 outlook 邮件

javascript - 如何获取 Google Analytics 全局函数名称?

javascript - 与可变参数回调异步并行

javascript - 如果窗口位置是 1.html,则使用 js 重定向

jquery - 如果多次使用 $(this) ,我应该在 jQuery 中缓存它吗?