Super simple yet impossible menu - html

How do I do this?
A menu with 3 links (A B C).
"A.html" is shown at start.
When link "B" is clicked, "A" is faded out and "B" fades in.
Every time a link is clicked. Content is changed by fadeout and fadein.
If possible I would like the browsers back buttom to work.
<div menu>
<link> A </link>
<link> B </link>
<link> C </link>
</div menu>
<div content>
A
</div content>

Try this: http://jsfiddle.net/fAvcq/9/
HTML
<div id="menu">
A
B
C
</div>
<div id="content">A</div>
CSS
.active {
color: red;
}
JS
$(document).ready(function(){
$('#menu a[class=active]').fadeOut('slow');
$('#menu a').click(function(){
$('#menu a[class=active]').fadeIn('slow');
$('#menu a[class=active]').removeClass();
$(this).addClass('active');
$('#menu a[class=active]').fadeOut('slow');
$('#content').html($(this).html());
});
});

you will need javascript or jquery for that
see your impossible possible below:
place your markup like this
<div class="menu">
<ul>
<li class="active">
<a href="#" > A </a>
<div class="A hidden">
<h1> Hello I am A </h1>
<img src="y.jpg">
</div>
</li>
<li>
<a href="#" > B </a>
<div class="B hidden">
<h1> Hello I am B </h1>
<img src="y.jpg">
</div>
</li>
</ul>
</div>
<div class="content">
</div>
and place a simple jQuery code like this:
//find the changeContent function to the click of anchors
$('a').on('click',function(){
changeContent(this);
});
//load the first content by default
changeContent($('li.active').find('a:first'));
function changeContent(target){
$('li').removeClass('active');
$(target).parent().addClass('active');
$('.content').html($(target).siblings('div').html());
}
TADA!! its done.
see this in live

Related

Bind child element position to parent element

I have a navigation that is horizontal. Under every choice I have a div that opens up on click. But the problem is that it binds it's position to the parent navigation button. I want every div that opens on the exact same spot. I want every child div that opens to open from the first element in the navigation bar.
So in this case i want the white open div to bind to "Nyheter" instead. I really can't solve it, I tried set a div element before the navigation that all div that opens binds to in css but it not seems to work.
<div class="Container">
<nav class="NavHorizontal Grid Grid--alignMiddle">
#Navigation.RenderNavigation("master/navigationDesignHeader.cshtml", navigationSettings)
</nav>
</div>
//NavigationDesignheader.cshtml under this line
var elementId = 1;
foreach (var node in nodes)
{
var idElement = "megaMenu" + elementId;
<div class="NavHorizontal-item Grid-cell u-sizeFit" id="#idElement">
<a class="Button Button--tab navigationHeaderLink u-pointer" onclick="toggleMenu('#elementId')">
#node.Name
</a>
#RenderMegaMenu(node.Nodes, node.Link, node.Name)
</div>
elementId++;
}
Megamenu:
<div>
<div id="megaMenuDropdown" class="Container megaMenuDropdown-content displayNone">
<div class="Grid Grid--withGutter">
<div class="Grid-cell u-sizefull u-mt-10">
#nodeName
<div class="megaMenuToggle-closeBars u-pointer" style="float:right">
<span class="megaMenuToggle-closeBar"></span>
<span class="megaMenuToggle-closeBar"></span>
</div>
</div>
</div>
<hr class="colorBlue" />
<div class="Grid Grid--withGutter">
<div class="Grid-cell u-size12of12 u-md-size6of12 u-lg-size6of12">
<ul>
#foreach (var node in firstColumn)
{
<li class="u-mb-10 linkHover">
<a class="userLink colorBlue" href="#node.Link">#node.Name</a>
</li>
}
</ul>
</div>
#if (moreThanTen)
{
<div class="Grid-cell u-size12of12 u-md-size6of12 u-lg-size6of12">
<ul>
#foreach (var node in secondColumn)
{
<li class="u-mb-10 linkHover">
<a class="userLink colorBlue" href="#node.Link">#node.Name</a>
</li>
}
</ul>
</div>
}
</div>
</div>
</div>
Any suggestions?

How to add a hover event handler in JQuery, that will just target sibling elements with the same parent element?

how to make hover over one div to trigger changes in another div, but not to affect to another div with Jquery. Here is example
I know for this option but It's not working for me
$(function() {
$(".single-holder-image").hover(function() {
$(".read-more-a-black", this).css('color', '#a2d0ba');
}, function() {
// on mouseout, reset the background colour
$(".read-more-a-black", this).css('color', '');
});
});
maybe I need to change html structure
<div class="big-holder">
<div class="single-post-holder">
<a class="" href="#">
<div class="single-holder-image">
<img src="https://i.picsum.photos/id/717/200/300.jpg?hmac=OJYQhMLNcYlN5qz8IR345SJ7t6A0vyHzT_RdMxO4dSc" alt="">
</div>
</a>
<div class="description-holder">
<p class="category name "></p>
<a class="read-more-a-black" href="#"><h5>Title 2</h5></a>
<a class="read-more-a-black-p" href="#">lorem test test test test</a>
<div class="pdf-holder">
<p>Tools:</p>
</div>
</div>
</div>
<div class="single-post-holder">
<a class="" href="#">
<div class="single-holder-image">
<img src="https://i.picsum.photos/id/717/200/300.jpg?hmac=OJYQhMLNcYlN5qz8IR345SJ7t6A0vyHzT_RdMxO4dSc" alt="">
</div>
</a>
<div class="description-holder">
<p class="category name "></p>
<a class="read-more-a-black" href="#"><h5>Title 2</h5></a>
<a class="read-more-a-black-p" href="#">lorem test test test test</a>
<div class="pdf-holder">
<p>Tools:</p>
</div>
</div>
</div>
</div>
Also, will I be able to do the same when the mouse is hover over the title to trigger image and gets a transform: scale?
Use $(this) in the .hover() event handler callback.
This way just the very element where the event occured will be selected.
After that some JQuery DOM traversing with .parents() and .find() and problem solved:
$(document).ready(function() {
$(".single-holder-image").hover(function() {
$(this).parents(".single-post-holder").find(".read-more-a-black").css('color', '#a2d0ba');
}, function() {
// on mouseout, reset the background colour
$(this).parents(".single-post-holder").find(".read-more-a-black").css('color', '');
});
});

Jquery Mobile - edit side-bar on load

I want to insert the name and picture to the side-bar dynamically. I tried this way but it works only for the first page and after navigation to another page, the span and the img tags are both empty:
Jquery:
$(document).on("pageshow", function(e) {
$("#nameFB").text("test");
$('#imgFB').attr('src', 'https://graph.facebook.com/' + fb_id + '/picture');
$('#nav-panel').trigger('create');
});
HTML:
<div id="home" data-role="page" class="ui-responsive-panel" >
<div data-role="header" data-theme="d">
</div>
<div data-role="panel" data-position="left" data-position-fixed="false" data-display="reveal" id="nav-panel">
<a href="Profile.html" data-role="button" id="profile">
<img src="" id="imgFB"/><span id="nameFB"></span> </a><br/>
<a href="Notifications.html" data-role="button" > Notifications </a><br/>
</div>
</div>
Thank you

The jquery accordion overlaps the content of my header

I am using the jquery accordion source for my website and what happens when I scroll down is the accordion overlaps my header.
I haven't made any adjustments to the CSS code in the accordion class so I don't have much to show but I've read a lot of people complaining that the accordion source from jquery UI has this problem but I have not been able to find out what it is?
Any ideas? Thanks!
<script>
JQuery(document).ready(function(){
$("#accordion").accordion();
});
</script>
</a>
</div>
<nav class="nav">
<div class="padded">
<ul>
<li class="active"><a id="link1" class="nav-section1" href="#section1">About</a></li>
<li><a id="link2" class="nav-section2" href="#section2">Design</a></li>
<li><a id="link3" class="nav-section3" href="#section3">3D + Animation</a></li>
<li><a id="link5" class="nav-section5" href="#section5">Video Production</a></li>
<li><a id="link6" class="nav-section6" href="#section6">Contact</a></li>
<li class="scrollTop"><span class="entypo-up-open"></span></li>
</ul>
</div>
</nav>
<div class = "accordion">
<article>
<h1 id="section1">About</h1>
<p>Farman Pirzada is this one dude who's pretty awesome and there's a lot you should learn about him because I love him</p>
</p>
</article>
and here's the CSS
#accordion {
padding-left: 100px;
}
http://imgur.com/EaQOT0g

Onclick for tab not working

This is what I have in my layout view. Home tab and To Do tab.
And codes in my html:
<div id="tabs">
<ul>
<li id="li_tab1" onclick="HomeTab"><a>Home</a></li>
<li id="li_tab2" onclick="ToDoTab"><a>To Do</a></li>
</ul>
<div id="Content_Area">
<div id="HomeTab">
<p>Home tab content goes here.</p>
</div>
<div id="ToDoTab" style="display: none;">
<p>To Do tab content goes here.</p>
The problem here is I tried to click on the To Do tab but it seems that the onclick is not working. Please help! Thanks.
//use this code istead of that..
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<div id="tabs">
<ul>
<li id="li_tab1">Home</li>
<li id="li_tab2">To Do</li>
</ul>
<div id="Content_Area">
<div id="HomeTab">
<p>Home tab content goes here.</p>
</div>
<div id="ToDoTab" style="display: none;">
<p>To Do tab content goes here.</p></div
Use this code it will work
Use this javascript it will work to hide the content
<script type="text/javascript">
var showcont = [];
var showcont_containers = [];
$('#tabs ul li a').each(function () {
// note that this only compares the pathname, not the entire url
// which actually may be required for a more terse solution.
if (this.pathname == window.location.pathname) {
showcont.push(this);
showcont_containers.push($(this.hash).get(0));
};
});
$(showcont).click(function(){
$(showcont_containers).hide().filter(this.hash).fadeIn();
});
</script>
You can use JQuery UI:
<script>
$(function() {
$( "#tabs" ).tabs();
});
</script>
<div id="tabs">
<ul>
<li>Tab 1</li>
<li>Tab 2</li>
</ul>
<div id="tabs-1">
<p>Content of Tab 1</p>
</div>
<div id="tabs-2">
<p>Content of Tab 2</p>
</div>
</div>
Check out this link for more information