javascript - jQuery click event stop working in plugin -
i've been trying add event listeners part of plugin. idea simple, goal slider plugin handles 2 dimensions (horizontally , vertically)
so have this
<div class="tab-container bg-dark-blue" start-tab="home"> <div class="tab-page" x-index="1" y-index="1" id="home"> <h1>x=1, y=1</h1> </div> <div class="tab-page" x-index="1" y-index="2"> <h1>x=1, y=2</h1> </div> <div class="tab-page" x-index="2" y-index="1"> <h1>x=2, y=1</h1> </div> <div class="tab-page" x-index="2" y-index="2"> <h1>x=2, y=2</h1> </div> </div>
where tab-page divs absolutely positioned 100% width , height, , tab-container relatively positioned 100% width , height of browser.
var __mymethods = { width : 0 height : 0, container : null, // other stuff setup : function(tab_container) { // setup __myplugin.container = tab_container // setup width, height of container }, /* * movement functions * */ move : function(direction) { if( direction == 'left' ) { __mymethods.x--; __mymethods.translate( 'left', __mymethods.width ); // } if( direction == 'right' ) { __mymethods.x++; __mymethods.translate( 'left', (-1)*__mymethods.width ); // } if( direction == 'up' ) { __mymethods.y--; __mymethods.translate( 'top', __mymethods.height ); } if( direction == 'down' ) { // __mymethods.y++; __mymethods.translate( 'top', (-1)*__mymethods.height ); // } }, translate : function(property, offset) { // each .tab-page in animate css property $(__mymethods.container).children(".tab-page").each( function() { var animation = {}; var x = parseint( $(this).css(property).replace('px','') ) + offset; animation[property] = x.tostring() + 'px'; $(this).animate( animation, { 'duration' : 0, 'queue' : false, } ); }); }, }; $.fn.myplugin = function() { __mymethods.setup(this); $(".btn").click( function(event) { __mymethods.move( $(this).attr("move") ); console.log(this); }); return this; };
so put
<button class="btn" move="up"></button> <button class="btn" move="down"></button> <button class="btn" move="left"></button> <button class="btn" move="right"></button>
somewhere in html , works fine up, left, right... if click move="down" button works first time.
i don't know why hapening, event never fires again if click button, tried doing console.log(this) inside click event function, doesn't show after down button clicked...
any idea of can happening?
thank can give me
edit: here demo
regards
in jsfiddle down button seems stay behind tab-page s. giving z-index menu , tab-page elements solves problem.
in css file: add
z-index: 10;
to .menu
add
z-index: 1;
to .tab-page
Comments
Post a Comment