繁体   English   中英

图片照片库

[英]Image photo gallery

我创建了一个图像照片库。

当我点击下一个和上一个按钮时,我将它设置为上下

当我点击prev和next时,我需要它并排。

这是演示

http://jsfiddle.net/T657N/16/

刚刚将top参数更改为脚本内部的left

在这里演示

你只需要改变你的javascript的SwapFirstLast()函数:

更换

 $(this).animate({ 'top' : direction + $(this).height() + 'px' }, 'slow', function() { //animate the img above/under the gallery (assuming all pictures are equal height)
  $(this).css('z-index', newZindex) //set new z-index
    .animate({ 'top' : '0' }, 'slow', function() { //animate the image back to its original position
      inAnimation = false; //reset the flag
    });
});

 $(this).animate({ 'left' : direction + $(this).height() + 'px' }, 'slow', function() { //animate the img above/under the gallery (assuming all pictures are equal height)
  $(this).css('z-index', newZindex) //set new z-index
    .animate({ 'left' : '0' }, 'slow', function() { //animate the image back to its original position
      inAnimation = false; //reset the flag
    });
});

所以最后你的功能将是:

function swapFirstLast(isFirst) {
if(inAnimation) return false; //if already swapping pictures just return
else inAnimation = true; //set the flag that we process a image

var processZindex, direction, newZindex, inDeCrease; //change for previous or next image

if(isFirst) { processZindex = z; direction = '-'; newZindex = 1; inDeCrease = 1; } //set variables for "next" action
else { processZindex = 1; direction = ''; newZindex = z; inDeCrease = -1; } //set variables for "previous" action

$('#pictures img').each(function() { //process each image
  if($(this).css('z-index') == processZindex) { //if its the image we need to process
    $(this).animate({ 'left' : direction + $(this).height() + 'px' }, 'slow', function() { //animate the img above/under the gallery (assuming all pictures are equal height)
      $(this).css('z-index', newZindex) //set new z-index
        .animate({ 'left' : '0' }, 'slow', function() { //animate the image back to its original position
          inAnimation = false; //reset the flag
        });
    });
  } else { //not the image we need to process, only in/de-crease z-index
    $(this).animate({ 'top' : '0' }, 'slow', function() { //make sure to wait swapping the z-index when image is above/under the gallery
      $(this).css('z-index', parseInt($(this).css('z-index')) + inDeCrease); //in/de-crease the z-index by one
    });
  }
});

return false; //don't follow the clicked link

}

希望它会对你有所帮助。

暂无
暂无

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

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