简体   繁体   English

使用Jquery和Javascript选择图片

[英]Selecting pictures with Jquery and Javascript

I'm testing out a layout on a website using 3 pictures here: 我在这里使用3张图片测试网站上的布局:

Schechterbusiness.info Schechterbusiness.info

the left button works, making it go through the pictures. 左按钮起作用,使其遍历图片。 But I can't figure out how to get the right button to work, which is supposed to scroll through the other way. 但是我无法弄清楚如何使正确的按钮正常工作,应该以另一种方式滚动。 I know there's probably a way to do it with arrays but I can't wrap my brain around it. 我知道可能有一种使用数组的方法,但是我无法绕开它。 Halp!

Code to scroll through pictures: 滚动浏览图片的代码:

$('#fryLink').click(function() {
        $('#hide').hide();
        $('#img').hide();

    count++;

        if(count == 1) {

        $('#img').attr("src","images/fry.png");

        }
        else if(count == 2) {

        $('#img').attr("src","images/bender.png");

        }
        else if(count == 3) {

        $('#img').attr("src","images/zoidberg.png");
        }


                $('#img').show("fade");





        if(count > 2) {

        count = 0;
        }

通常,只需使用与其他方法相同的功能就足够了

count--;

following the first answere 跟随第一个答案

Bind event to right mouse click 将事件绑定到鼠标右键

reverse the counter ;) 逆转柜台;)

Try this 尝试这个

var count = 0;
var imgLength = 3;
$('#leftLink , #rightLink').click(function() {
    $('#hide').hide();
    $('#img').hide();
    if (this.id === 'leftLink') {
        count--;
        if (count < 0) {
            count = imgLength-1;
        }
    }
    else {
        count++;
        if (count > imgLength-1) {
            count = 0;
        }
    }
    var src = "images/fry.png";

    if (count == 1) {
        src = "images/bender.png";
    }
    else if (count == 2) {
        src = "images/zoidberg.png";
    }
    $('#img').attr('src',src).show("fade");
});​

You have count cycling through four states: 0, 1, 2, and 3. But you only set the image for states 1 - 3. 您有四个状态循环count :0、1、2和3。但是,您仅将图像设置为状态1-3。

This leads to duplicating one image--whichever was the last one--when your count variable is on 0. 当您的count变量为0时,这会导致复制一张图片-以最后一张为准。

As to helping you get exactly what you want, unfortunately that is not really clear. 不幸的是,关于帮助您准确获得所需的东西。 Are the three buttons supposed to be a sort of "forward / something / reverse"? 这三个按钮是否应该是一种“前进/后退/倒退”? What do you want to happen when the center button is clicked on? 单击中心按钮时,您想做什么?

Also, making the buttons display the proper pointer/hand icon is important. 同样,使按钮显示正确的指针/手形图标也很重要。 Right now they show the text selection bar instead, and that makes it confusing since it conveys to the user that the items are not clickable. 现在,他们改为显示文本选择栏,这使它感到困惑,因为它向用户传达了不可单击的项目。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM