I cannot seem to figure out the solution to my problem. Through intense several days of research I've concluded this stack overflow question is similar and may be a solution (GetElementByID - Multiple IDs), but with all my trials I still can't seem to implement the solution to my code. [DEMO]. I've asked the same question many times with variations, but I still keep getting broad answers that never help at all. My question is, How can I create multiple ID'S from the script to perform several open-transitons?
/*!
* classie - class helper functions
* classie.has( elem, 'my-class' ) -> true/false
* classie.add( elem, 'my-new-class' )
* classie.remove( elem, 'my-unwanted-class' )
* classie.toggle( elem, 'my-class' )
*/
/*jshint browser: true, strict: true, undef: true */
/*global define: false */
(function (window) {
'use strict';
// class helper functions from bonzo https://github.com/ded/bonzo
function classReg(className) {
return new RegExp("(^|\\s+)" + className + "(\\s+|$)");
}
// classList support for class management
// altho to be fair, the api sucks because it won't accept multiple classes at once
var hasClass, addClass, removeClass;
if ('classList' in document.documentElement) {
hasClass = function (elem, c) {
return elem.classList.contains(c);
};
addClass = function (elem, c) {
elem.classList.add(c);
};
removeClass = function (elem, c) {
elem.classList.remove(c);
};
} else {
hasClass = function (elem, c) {
return classReg(c).test(elem.className);
};
addClass = function (elem, c) {
if (!hasClass(elem, c)) {
elem.className = elem.className + ' ' + c;
}
};
removeClass = function (elem, c) {
elem.className = elem.className.replace(classReg(c), ' ');
};
}
function toggleClass(elem, c) {
var fn = hasClass(elem, c) ? removeClass : addClass;
fn(elem, c);
}
var classie = {
// full names
hasClass: hasClass,
addClass: addClass,
removeClass: removeClass,
toggleClass: toggleClass,
// short names
has: hasClass,
add: addClass,
remove: removeClass,
toggle: toggleClass
};
// transport
if (typeof define === 'function' && define.amd) {
// AMD
define(classie);
} else {
// browser global
window.classie = classie;
}
})(window);
/**
* main.js
* http://www.codrops.com
*
* Licensed under the MIT license.
* http://www.opensource.org/licenses/mit-license.php
*
* Copyright 2014, Codrops
* http://www.codrops.com
*/ (function () {
var bodyEl = document.body,
content = document.querySelector('.content-wrap'),
openbtn = document.getElementById('open-button'),
closebtn = document.getElementById('close-button'),
isOpen = false;
function init() {
initEvents();
}
function initEvents() {
openbtn.addEventListener('click', toggleMenu);
if (closebtn) {
closebtn.addEventListener('click', toggleMenu);
}
// close the menu element if the target it´s not the menu element or one of its descendants..
content.addEventListener('click', function (ev) {
var target = ev.target;
if (isOpen && target !== openbtn) {
toggleMenu();
}
});
}
function toggleMenu() {
if (isOpen) {
classie.remove(bodyEl, 'show-menu');
} else {
classie.add(bodyEl, 'show-menu');
}
isOpen = !isOpen;
}
init();
})();
Though I figured out specifically.
var bodyEl = document.body,
content = document.querySelector('.content-wrap'),
openbtn = document.getElementById('open-button'),
closebtn = document.getElementById('close-button'),
isOpen = false;
They are two buttons shown as three gray dots if you scroll towards the middle of the result screen. The first set of gray dots will open two black boxes. I do not want that. I would only like the first set of gray dots to only open the first box, the second set of gray dots to only open the second box, and so on.
I figured this portion of the javascript was what was needed to be altered in order to achieve this, though like I said before I cannot seem to implement the solution. Can some very bright mind help me figure this out! no advice please!, just a straight forward answer which solves the problem!
CAN SOMEONE PLEASE HELP ME, IVE SEEN USERS ANSWER WITH PARAGRAPHS OF CODE, MY QUESTION IS NOT AT ALL TOO DIFFICULT FOR THE EXPERIENCED AND I KNOW IT HAS BEEN DONE BEFORE!!.