javascript - Open fancybox from function -


i trying open fancybox function have - in short html code looks this;

<a href="#modalmine" onclick="myfunction(this); return false;">   click </a> 

and part of function looks this;

function myfunction(me) {     $(me).fancybox({         'autoscale': true,         'transitionin': 'elastic',         'transitionout': 'elastic',         'speedin': 500,         'speedout': 300,         'autodimensions': true,         'centeronscroll': true,     }); } 

the above works in ie not in firefox or chrome - idea how can fix this? know 1 why trigger link, hope solution possible.

since you're using jquery, stop binding event handlers in html, , start writing unobtrusive javascript.

$(document).ready(function () {     function myfunction(me)     {         $(me).fancybox({             'autoscale': true,             'transitionin': 'elastic',             'transitionout': 'elastic',             'speedin': 500,             'speedout': 300,             'autodimensions': true,             'centeronscroll': true // remove trailing comma!!         }).click();         // fire click event after initializing fancybox on element         // should open fancybox     }      // use .one() handler executed @ once per element     $('a[href=#modalmine]').one('click', function ()     {         myfunction(this);         return false;     }); }); 

however, don't particularly see reason setting fancybox on click. instead:

$(document).ready(function () {     function myfunction()     {         // note use of "this" rather function argument         $(this).fancybox({             'autoscale': true,             'transitionin': 'elastic',             'transitionout': 'elastic',             'speedin': 500,             'speedout': 300,             'autodimensions': true,             'centeronscroll': true         });     }      $('a[href=#modalmine]').each(myfunction); }); 

basic demo (no images) →


Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -