javascript - How can I use different hrefs in my fancybox call? -


i have following fancybox call:

  $(document).ready(function() {         $('.fancybox').fancybox({             'closeclick'  : false,             'scrolling'   : 'no',              aftershow: function(){             //do stuff                }         });     }); 

for influence on following:

<a href="example_url" class="fancybox fancybox.iframe"><img src="example"/></a> 

what add href fancybox call can put hash tag in href in html.

  $(document).ready(function() {         $('.fancybox').fancybox({             'closeclick'  : false,             'scrolling'   : 'no',                 'href'        : 'example_url',              aftershow: function(){             //do stuff                }         });     }); 

but need take bit further. lets have 3 different items consider:

<a href="#" class="fancybox fancybox.iframe"><img src="example"/></a> //requires url-1 <a href="#" class="fancybox fancybox.iframe"><img src="example"/></a> //requires url-2 <a href="#" class="fancybox fancybox.iframe"><img src="example"/></a> //requires url-3 

i know need give each 1 type of unique identifier. further, realize make 3 different fancybox calls each one, think better way this:

  $(document).ready(function() {         $('.fancybox').fancybox({                 //do processing here find out triggered fancybox, set variable proper href based on input. have switch statement etc             'closeclick'  : false,             'scrolling'   : 'no',                 'href'        : //variable holding proper url              aftershow: function(){             //do stuff                }         });     }); 

but having trouble making happen how envision!

edit: should example using fancybox 2, not work in earlier versions

you can have links carry data-href attribute, can use in fancybox call (fiddle: http://jsfiddle.net/xetz8/)

<a class="fancybox" data-href="http://fiddle.jshell.net/ytwct/show/" href="#">url 1</a>  <a class="fancybox" data-href="http://doc.jsfiddle.net/use/echo.html" href="#">url 2</a> 

and js

$(function() {     $('.fancybox').fancybox({         type: 'iframe',         beforeload: function() {             this.href = this.element.data('href');         }     }); }); 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -