1

I would like to be able to change the width of my div using the mousewheel.
I guess this is very hard to do (at least to hard for me), but I thought maybe someone has ever written such a jquery or javascript code.

To put in some context: here is the relevant part of my website: http://jsfiddle.net/XGERP/1/
And here is the complete website. I would like the user to decide how big the #main div is going to be.

4

2 回答 2

8

这里有一些 jquery 来满足你的幻想。经测试可在 Chrome、Firefox 和 IE11 中运行。

$(document).ready(function(){
    $('#main').bind('wheel mousewheel', function(e){
        var delta;

        if (e.originalEvent.wheelDelta !== undefined)
            delta = e.originalEvent.wheelDelta;
        else
            delta = e.originalEvent.deltaY * -1;

            if(delta > 0) {
                $("#main").css("width", "+=10");
            }
            else{
                $("#main").css("width", "-=10");
            }
        });
    });
于 2013-06-24T19:54:08.200 回答
0

你可以使用 Jquery Zoom ...

http://www.jacklmoore.com/zoom/

然后,就在用户悬停时,他们可以读得更近一些......

不确定它是否适用于文本,但还没有真正研究过

或者你可以做这样的事情......

 $('#main').mousewheel(function(event, delta) {
var delta_px = delta > 0 ? "+=50" : "-=50";
$(this).css('width', delta_px);
});

您需要mousewheel为此的扩展插件...

http://archive.plugins.jquery.com/project/mousewheel

这是一个工作演示,鼠标滚轮脚本高于一切,然后你想要的实际 jquery 在底部

在这里演示

于 2013-06-24T19:48:09.533 回答