2012-01-05 103 views
0

JQuery UI滑动属性存在问题。这将产生一个温和滑出当前图像的同时,下一个图像轻轻滑入。JQuery平滑滑动图库

$(document).ready(function(){ 
    $('.gallery img').hide(); $('.gallery img:first').show().addClass('galo'); 


    $('.galarr.r).click(function(){ 
     var next = $('.galo').next(); 
     $('.galo').hide('slide', {direction:'left'}, {duration:800, queue:false}).removeClass('galo'); $(next).show('slide', {direction:'right'}, {duration:800, queue:false}).addClass('galo'); 
}); 

}); 

我们的网站上它,而不是滑动旧的,留下的空白区域,然后下一个图像突然出现。

我已经设置了一个简单的小提琴,尽管有相同的代码,根本不起作用。问题是什么。

http://jsfiddle.net/W27YK/7/

Firebug的报道,nextslide()是不是当它很清楚的是小提琴的功能。

+0

看起来像你的jsfiddle,和你的代码插入到的问题不匹配。哪一个是你想要帮助的人?在您粘贴的代码中,请注意您在.galarr.r之后缺少选择器 – PriorityMark 2012-01-05 17:18:56

回答

1

这是我认为你正在努力完成的工作jsFiddle

有几件事要记住。

  • 如果元素绝对定位,幻灯片效果往往效果更好。我将其添加到.gallery img的样式中。
  • 当放置在相对位置的父框中时,绝对定位的项目效果最好,否则它们对于页面是绝对的,而不是相对于父项的绝对定位(这是预期的功能)
  • 您会注意到这也固定了右键/ img的位置,因为它位于文档正文右侧15像素处,而不是右侧边缘15像素处。
  • 我注意到你的按钮是错误的高度,并将其更新为精灵图像的高度。出于某种原因,它正在扰乱我;)。

,将该代码......你修改后的CSS:

.gallery { position: relative; width:700px; height:370px; border-bottom:1px solid #DDD; overflow:hidden; } 
.gallery img { width:700px; height:370px; border:0px; position: absolute;} 

.gallery a.galarr.l { position:absolute; width:28px; height:50px; background:url(http://www.golfbrowser.com/wp-content/themes/RIK/images/core/galarr.png) left top no-repeat; position:absolute; top:160px; left:15px; display:block;} 
.gallery a.galarr.r{ position:absolute; width:28px; height:50px; background:url(http://www.golfbrowser.com/wp-content/themes/RIK/images/core/galarr.png) right top no-repeat; position:absolute; top:160px; right:15px; display:block;} 

而且修改后的javascript:

$(document).ready(function() { 
    $('.gallery img').hide(); 
    $('.gallery img:first').show().addClass('galo'); 

    $('.galarr').click(function() { 
     // one event handler to rule them all, both left and right! 
     var $next, slideOutDir = ''; 

     // figure out what direction the images are sliding, and act accordingly. 
     if ($(this).hasClass('l')) { 
      slideOutDir = "right"; 
      // figure out rather the next slide is there, or we need to wrap to the end 
      $next = $('img.galo').prev('img').length ? $('img.galo').prev('img') : $("img:last"); 
     } 
     else { 
      slideOutDir = "left"; 
      // figure out rather the next slide is there, or we need to wrap to the beginning 
      $next = $('img.galo').next('img').length ? $('img.galo').next('img') : $(".gallery img:first"); 
     } 

     if (!$next.length) { 
      $next = $(".gallery img:first"); 
     } 
     //$next.css('z-index', 5); 
     //$('img.galo').css('z-index', 1); 
     $('img.galo').hide('slide', { 
      direction: slideOutDir 
     }).removeClass('galo'); 
     $next.show('slide', { 
      direction: (slideOutDir === "left" ? 'right' : 'left') 
     }).addClass('galo'); 
    }); 

});