javascript - Zoom div content on scroll - Stack Overflow

I want to make div content resizable, but the div itself to stay the same size. This should happen when

I want to make div content resizable, but the div itself to stay the same size. This should happen when the user scrolls. I have this function:

var zoomable = document.getElementById('zoomable'),
    zX = 1;
window.addEventListener('wheel', function (e) {
    var dir;
    if (!e.ctrlKey) {
        return;
    }
    dir = (e.deltaY > 0) ? 0.1 : -0.1;
    zX += dir;
    zoomable.style.transform = 'scale(' + zX + ')';
    e.preventDefault();
    return;
});

This works but only with the div itself. In this div I have multiple small draggable tables with .foo class and I want to resize them without changing parents size. I have also tried this:

var zoomable = document.getElementsByClassName('foo'),
    zX = 1;
window.addEventListener('wheel', function (e) {
    var dir;
    if (!e.ctrlKey) {
        return;
    }
    dir = (e.deltaY > 0) ? 0.1 : -0.1;
    zX += dir;
    zoomable.each(function(){ 
        $(this).style.transform = 'scale(' + zX + ')'; 
    })
    e.preventDefault();
    return;
});

But is does not work either. Is there a way to resize content but not the div?

EDIT: Here is jsfiddle: / It's not exactly my project (Because it's too plex), but the idea is the same. I want to make #zoomable div to stay the same size and its content (paragraphs in this case) to be resizable.

I want to make div content resizable, but the div itself to stay the same size. This should happen when the user scrolls. I have this function:

var zoomable = document.getElementById('zoomable'),
    zX = 1;
window.addEventListener('wheel', function (e) {
    var dir;
    if (!e.ctrlKey) {
        return;
    }
    dir = (e.deltaY > 0) ? 0.1 : -0.1;
    zX += dir;
    zoomable.style.transform = 'scale(' + zX + ')';
    e.preventDefault();
    return;
});

This works but only with the div itself. In this div I have multiple small draggable tables with .foo class and I want to resize them without changing parents size. I have also tried this:

var zoomable = document.getElementsByClassName('foo'),
    zX = 1;
window.addEventListener('wheel', function (e) {
    var dir;
    if (!e.ctrlKey) {
        return;
    }
    dir = (e.deltaY > 0) ? 0.1 : -0.1;
    zX += dir;
    zoomable.each(function(){ 
        $(this).style.transform = 'scale(' + zX + ')'; 
    })
    e.preventDefault();
    return;
});

But is does not work either. Is there a way to resize content but not the div?

EDIT: Here is jsfiddle: https://jsfiddle/vaxobasilidze/ba2n9a61/ It's not exactly my project (Because it's too plex), but the idea is the same. I want to make #zoomable div to stay the same size and its content (paragraphs in this case) to be resizable.

Share Improve this question edited Nov 27, 2017 at 9:24 Vaxo Basilidze asked Nov 27, 2017 at 8:53 Vaxo BasilidzeVaxo Basilidze 1,05716 silver badges37 bronze badges 4
  • Please create a working fiddle. – dom_ahdigital Commented Nov 27, 2017 at 8:56
  • @dom_ahdigital I've added jsfiddle. If you could help me with this, I would be really glad. – Vaxo Basilidze Commented Nov 27, 2017 at 9:11
  • @VaxoBasilidze I've made fiddle for you in my answer is that what you want ? – Zvezdas1989 Commented Nov 27, 2017 at 9:34
  • What browser are you using to test this? In everyone's fiddles I see no resizing or animation whatsoever. – dom_ahdigital Commented Nov 27, 2017 at 9:41
Add a ment  | 

1 Answer 1

Reset to default 4

I've adjusted your fiddle to work. I think this is what you wanted. You need to target your content to make this work like your description.

var content = document.getElementById('zoomable').getElementsByTagName('p');
var zX = 1;
window.addEventListener('wheel', function (e) {
    var dir;
    if (!e.ctrlKey) {
        return;
    }
    dir = (e.deltaY > 0) ? 0.1 : -0.1;
    zX += dir;
    for (var i = 0; i<content.length; i++) {
         content[i].style.transform = 'scale(' + zX + ')';
        }

    e.preventDefault();
    return;
});

https://jsfiddle/Karadjordje1389/z254o87v/

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745367923a4624668.html

相关推荐

  • javascript - Zoom div content on scroll - Stack Overflow

    I want to make div content resizable, but the div itself to stay the same size. This should happen when

    5小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信