图片库/缩放幻灯片

发布于 2024-11-24 01:51:03 字数 396 浏览 2 评论 0原文

我想做类似的事情。

在这种情况下,当用户单击图像时,该图像将以 100% 的浏览器高度显示,用户可以转到下一张/上一张图像。当用户再次单击时,图像将以更大的尺寸显示(可能是实际尺寸),并且用户可以在图像中上下移动,但无需滚动,只需移动鼠标即可。

我想要做的是,当用户第一次单击图像时,直接转到最后一步:与鼠标移动同步上下的最大图像,并且可以转到下一个图像。换句话说,混合了原始案例的第一步和第二步的特征。

在哪里可以看到教程或演示?或者我该怎么做?

谢谢

I wanted to do something similar to this.

In this case when the user click in the image, this images is showed with 100% of the browser height, and the user can go to the next/previous image. When the user clicks again the image is showed in a bigger size(may be in the real size) and the user can go up and down in the image, but with out scroll, just moving the mouse.

What I want to do is when the user click the first time in the image go right to the last step: The biggest image with up and down synchronized with the mouse movement, and the possibility to go to the next image. In other words a mix with the features of the first and the second step of the original case.

Where I can see a tutorial, or a demo?? or how can I do the this??

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

云柯 2024-12-01 01:51:03

基本上,您想做的事情分为三个部分。

  1. 单击图像将显示相对于浏览器高度的图像
  2. 您在此模式下可以转到下一个图像
  3. 再次单击该图像将进入超大模式,其中鼠标位置决定您正在查看图像的哪一部分 。

我不会写整个小提琴来证明这一点,因为这是一项相当大的工作量,但我可以告诉你基本的想法

使用 #1,当您单击图像时,您将创建一个新的 div,其 z-index 具有较高的数字(例如 9999)。该位置将是固定,并且您将创建

$(window).resize(function() {

    var windowheight = $(window).height();
    $("#imgdiv").css("height", windowheight);
});

如果用户决定调整窗口大小,它将调整图像大小,这样它始终占据浏览器的整个高度。

对于 #2,箭头只是创建一个新的 img 标签。这个想法类似于

function loadnew() {

    // create the new image
    var newimg = "<img id='newimg'></img>"
    $("#imgcontainer").append(newimg);

    // make sure it has the same classes as the current img
    // so that it's in the same position with an higher z-index
    // then load the image
    $("#newimg").addClass( "class1 class2" );
    $("#newimg").css( "z-index", "+=1" );
    $("#newimg").css( "opacity", 0 );

    $("#newimg").attr("src", "url/to/img");

    // animate the thing and then replace the src of the old one with this new one
    $("#newimg").animate( {
        opacity: 1;
    }, 1000, function() {
        $(oldimg).attr("src", $("#newimg").attr("src"));
    });
}

现在的#3,您将根据宽度调整图像的大小。 div fixed 定位。同样,您需要

$(window).resize(function() {

    var windowwidth= $(window).width();
    $("#imgdiv").css("width", windowwidth);
});

确保它始终占据整个屏幕。对于鼠标移动,您需要一个 mousemove 事件处理程序,

$("#superimgdiv").mousemove( function(e) {

    // need to tell where the mouse is with respect to the window
    var height = $(window).height();
    var mouseY = e.pageY;
    var relativepct = mouseY/height;

    // change the position relative to the mouse and the full image height
    var imgheight = $("superimg").height();
    $("superimgdiv").css("top", -1*relativepct*imgheight);
});

仅此而已。当然,我省略了一些细节,但这是总体思路。希望这可以帮助您入门。祝你好运。

Basically, there are three parts to what you want to do.

  1. Clicking on the image will show the image with respect to browser height
  2. You can go to the next image while you are in this mode
  3. Click on that image again will go into a supersize mode where your mouse position dictates what part of the image you are looking at

I'm not going to write a whole fiddle to demonstrate this because it's a decent amount of work but I can tell you the basic ideas.

With #1, when you click on the image, you will create a new div with a z-index of some high number (like 9999). The position would be fixed, and you will create

$(window).resize(function() {

    var windowheight = $(window).height();
    $("#imgdiv").css("height", windowheight);
});

Which will resize the image if the user decides to resize your window, this way it's always taking up the full height of your browser.

With #2, the arrows just create a new img tag. And the idea is something like

function loadnew() {

    // create the new image
    var newimg = "<img id='newimg'></img>"
    $("#imgcontainer").append(newimg);

    // make sure it has the same classes as the current img
    // so that it's in the same position with an higher z-index
    // then load the image
    $("#newimg").addClass( "class1 class2" );
    $("#newimg").css( "z-index", "+=1" );
    $("#newimg").css( "opacity", 0 );

    $("#newimg").attr("src", "url/to/img");

    // animate the thing and then replace the src of the old one with this new one
    $("#newimg").animate( {
        opacity: 1;
    }, 1000, function() {
        $(oldimg).attr("src", $("#newimg").attr("src"));
    });
}

Now with #3, you will size the image with respect to the width. The div fixed positioned. So again, you need a

$(window).resize(function() {

    var windowwidth= $(window).width();
    $("#imgdiv").css("width", windowwidth);
});

to make sure it's always taking up the whole screen. And for the mouse movement, you need to have a mousemove event handler

$("#superimgdiv").mousemove( function(e) {

    // need to tell where the mouse is with respect to the window
    var height = $(window).height();
    var mouseY = e.pageY;
    var relativepct = mouseY/height;

    // change the position relative to the mouse and the full image height
    var imgheight = $("superimg").height();
    $("superimgdiv").css("top", -1*relativepct*imgheight);
});

And that's it. Of course I'm leaving out a bunch of details, but this is the general idea. Hopefully this can get you started. Good luck.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文