2014-09-01 60 views
0

嗨,大家好我试图通过这个代码在漂亮的照片

$('.pp_next').on('click',function(){ 
     console.log('next'+Math.random()); 
     return false; 
    }); 

http://www.no-margin-for-errors.com/projects/prettyphoto-jquery-lightbox-clone/#prettyPhoto捕捉prettyphoto的下一个事件,但它无法正常工作的下一个事件。我想漂亮的照片代码可能会返回false或stoppropogation那里。任何帮助?

+0

我想你可以说你没有考虑足够大的误差范围... – royhowie 2014-09-01 20:55:14

+0

您确定这是正确的课程吗?画廊也有.pp_arrow_next和.pp_arrow_previous。 – TheFrozenOne 2014-09-01 20:57:53

回答

0

取决于你如何使用prettyPhoto div层寻找是保持主图像或视频等的javascript div层代替该层的在画廊例如内容(或者通过一个定时器自动OR由用户点击上一页/下一页)

而不是试图捕捉“点击”,专注于“改变”。 (假设你想要一个完全独立的方法/函数来捕获它),因为prettyPhoto初始化的内置参数可以在首次初始化prettyPhoto时调用“changepicturecallback:function(){}”时添加相同的内容,我将在此答案的底部显示为“选项2”)

例如在Gallery实现中,您应该在呈现的页面中看到类似于以下html div id的内容(img名称和样式值将会是不同的):

<div id="pp_full_res"> 
    <img id="fullResImage" src="/image.jpg" 
    style="height: 375px; width: 500px;" /> 
</div> 

项1)对于prettyPhoto INI的外部的单独的方法tialization - 您可以使用console.log或临时警报来查看每个div ID上的onchange事件捕获,以查看哪些工作正常,然后您的jQuery方法应该可以工作。喜欢的东西:

$('#fullResImage').on('change',function(){ 
    console.log('next'+Math.random()); 
    return false; 
}); 

$('#fullResImage').change(function() { 
    alert("Handler for .change() called."); 
    return false; 
});  

一旦你已经得到了确定的onChange,那么你可以将任何东西或改变DOM。

选项2)内置参数版本使用 内置参数中的可选项可以在正开始被添加像这样:

$("#theDivLayerToAttachPrettyPhoto").prettyPhoto({ 
     animation_speed: 'fast', /* fast/slow/normal */ 
     slideshow: 5000, /* false OR interval time in ms */ 
     autoplay_slideshow: false, /* true/false */ 

     /* changepicturecallback Called every time an item is shown/changed */ 
     changepicturecallback: function(){ 
      console.log('next'+Math.random()); 
     }, 
     autoplay: true /* Automatically start videos: True/False */ 
     //etc. other settings for your intialization 
});