I have a list that serves as a menu. Every time a user clicks on one of the elements in the list, I want a more detailed div be able to move from left to right.
So, if the user first clicked on the menu item A , A move from left to right. If the user then presses B , A moves from right to left (disappears from the screen) and B goes into slides.
I searched for this problem and found this post . I included the code from jsfiddle , but it did not work. There are no errors in the js log in the Chrome debugging tool. Nothing happens when I click on any item in a menu. What am I doing wrong?
<div class="project"> <ul id="project_menu" class="project_menu"> <li id="menu-php-mysql" data-projectID="php-project">PHP/MySQL</li> <li id="menu-nodejs" data-projectID="node-project">NodeJS</li> </ul> <div class="project-detail"> <div id="php-project"> <i class="ion-ios-close-empty close-icon js-close-icon"></i> <div classs="project-text"> </div> </div> <div id="node-project"> <i class="ion-ios-close-empty close-icon js-close-icon"></i> <div classs="project-text"> </div> </div>
#php-project { background-color: #9b59b6; margin: 30px; display: none; } $(document).ready(function() { itemsToRender = []; $('ul#project_menu li').click(function(e) { menuItemId = (e.currentTarget.id); $('.common').hide(); $(getProjectId(menuItemId)).css('display', 'inline'); var value = $(getProjectId(menuItemId)).css('right') === '100px' ? '-100px' : '100px'; $(getProjectId(menuItemId)).animate({ right: value }, 800); }); }); function getProjectId(menuItemId) { if (menuItemId.indexOf('php') > 0) { return '#php-project'; } else if (menuItemId.indexOf('node') > 0) { return '#node-project'; } else if (menuItemId.indexOf('angular') > 0) { return '#angular-project'; } else if (menuItemId.indexOf('mean') > 0) { return '#mean-project'; } }
Update1 : @ user5325596 indicated that my display property for the div part is set to none, so I fixed this by adding the following:
$(getProjectId(menuItemId)).css('display', 'inline-block');
right after $('.common').hide() .
Now, when I click on a menu item, I can see the div detail, but it doesnβt enliven.
Update2 . I downloaded jsFiddle , it includes the jquery animation that I successfully use (fadeIn, which is commented out), as well as the code suggested by elchininet.