Here i made an example of my menu jsfiddle. So i have horizontal menu with drop down, but what i need is - on page load first li should be expanded(this is not hard) and when i hover on any other element it should display current expanded content(and if i mouseleave current element should be expanded).
This is the situation when i hover on Item2 and mouseleave Item2 it should stay like this:
Item1 Item2 Item3
|||||
subItem2.1 subItem2.2 subItem2.3
UPDATE:
i managed to do it, but with exception, here is the link on JSFiddle
Its works as i wanted, but when i click on a link Item1 , or Item2 , init() function is called, and Item1 , active again, i need somehow to set active link - clicked one,
for example if i clicked on a Item3 link it redirects me to Item3 page and this link is active in menu.
(all code on Jsfiddle)
If I understand your question correctly, the problem is that you need to call the init function to redraw all, but at the same time you set there item1 as current; and this is not ok if you have just pressed link2.
If think that your solution should be to almost remove all the init code. All this can be done in the css styles, simplifying a lot your code.
you set active to items. (You are already doing this in the anchors, do it in the li). Then, put all the appearance styles inn the css, and your script is reduced.
don't need to set active on subitems. you can set rules like li.active li; that is, the li that is descendant of the active li.
Once you do all this, you can avoid the init funcion altogether.
Added fiddle
I have changed that in the updated fiddle
I am marking the visible item menu 'current', I find 'active' confusing for a class name. It must be in the li and not in the, so that it can affect the second level lis
Now the script is just
$(document).ready(function() {
$("#menu_item ul.menu li.expanded").mouseover(function(){
var previous = $('.current');
previous.removeClass('current');
$(this).addClass('current');
});
});
I am just removing current from the previous current element, and adding it to the new one.
The initial selection is just in the markup
<div id="menu_item">
<ul class="menu">
<li class="expanded first current">
Item1
And the new css rules are:
#menu_item > ul.menu > li.current {
background-color: orange;
}
#menu_item ul.menu li ul {
display: none;
}
#menu_item ul.menu li.current ul {
display: block;
}
you should doing changes in your style than its can work properly.
ul.menu li.expanded ul {
position: relative;
display: block;
top: 20px;
background-color: orange;
}
I am thinking that maybe URL targeting active state might be something you would be interested in. You can get the current path with JavaScript using window.location.pathname. You can check with jQuery using something like:
$(".first a[href=" + window.location.pathname + "]").addClass('active');
This will add the active class to all anchors in .first that have the same href attribute as the current path. You may need to trim the leading slash.
Please check out this article on active states.
You may also be interested in jQuery UI tabs.
Here is another jQuery UI tabs in standard practice.
Related
I am building a roadmap kind of thing on my website, the plan is if you hover over the green dots some speech bubbles should pop up. .road1 is the class of the first green dot and .road1k is the card or speech bubble that should show up. .road1 reacts to :hover as it is making the dot bigger as intended but somehow .road1k is still not showing up.
Here is my code:
.road1 {
display: block;
}
.road1k {
display: none;
}
.road1:hover {
-webkit-transform: scale(1.1);
}
.road1:hover .road1k {
display: block!important;
}
And my site
http://rebitsoft.dev.rebitsoft.com/
You might change the language on the top right corner to see the green dots on the mainpage.
Your CSS definition is targeting elements with .road1k within elements that have the road1 class. In your html structure, road1k is not contained by a .road1 element. Please see https://stackoverflow.com/a/13444826/8083244 for better details.
Include JQuery Library (head script):
<script src="http://rebitsoft.dev.rebitsoft.com/wp-includes/js/jquery/jquery.min.js?ver=3.6.0"></script>
A simple JQuery solution would be something like (footer script):
$('.road1').hover(function() {
$('.road1k').show();
}, function(){
$('.road1k').hide();
});
Leaving as an answer because I don't have the rep to comment on the question.
Edit - added outFunction to hover
I have the following HTML:
<ul id='x'>
<li>
<a class="document-web1" data-href="/x">x</a>
</li>
<li>
<a class="document-web2" data-href="/y">y</a>
</li>
</ul>
I set up this event:
$("#content-button-panel")
.on('click', 'a', function (event) {
event.preventDefault();
var $link = $(this);
getContentAjax($link);
});
This works but when my cursor moves over the text it changes
to a vertical text select bar instead of a pointer. Is there
some way that I can make the cursor always appear as an
arrow when it's over any part of the li element?
If you just want to change the cursor you can use this in your CSS:
li
{
cursor: default;
/*cursor: pointer;*/
}
Plus if you’re not really sure which property render which cursor, check the following link it will clear your confusion.
CSS Cursors
after read your title its looks like you want
li:hover{
cursor:pointer;
}
the above will make cursor like
but after reading your whole question
li:hover{
cursor:default;
}
and this will will show cursor like
also check this its pretty cool with live view
now i would suggest you to write relevant title
I am a little new to jquery myself, but I believe you have to use onhover or onmouseover rather than on click.
You can use the cursor property of css, that is css(cursor, pointer), for example
The css property you want is pointer. setting it to the default value will force the browser to render the pointer as an arrow even though there is no href attribute on the a element.
#x a {
cursor:default;
}
is there a way with pure css to Have a link that might say "New! Watch Video" and then once someone has clicked the link have it remove the "New" portion of the link. I'm assuming this can be done w/ Jquery but I'd like to see if there is an way to remove it with just css.
Rather than removing words, add the word "New" if the link hasn't been visited yet
a:before {
content: "New! ";
}
a:visited:before {
content: "";
}
No extra markup, and you don't need to put the word "New" everywhere.
Wrap the "New!" in a span inside the anchor:
<a class="newText" href="somepage.html"><span>New! </span>Watch video</a>
and in your CSS, set:
a.newText:visited span { display: none; }
I would recommend using a class on the anchor (like "newText" above) so that this formatting will only be applied to the links you want it on. And keep in mind that the "New!" text will reappear if the user clears their browser history.
Assuming the anchor will take you to a new page you can use the following technique:
a:before {
content: "New! ";
}
On any page you wish to remove or change it, you can add a body class
body.blah a:before {
content: "";
}
I've made a button that expands horizontally: http://jsfiddle.net/timkl/TsDud/
However I'm having a hard time getting my button's hover-state to work properly.
This is my markup:
<a class="action-button" href="#"><span>Some text</span></a>
I don't know how to style the hover-effect so that the entire button is "lit" when the user hovers over a part of the button that isn't covered by the <span>.
This is what I get when I hover over a part of the button that isn't covered by the <span>:
Check out my example here: http://jsfiddle.net/timkl/TsDud/
jsFiddle DEMO HERE
Change the last lines to:
a.action-button:hover > span
Ex:
a.action-button:hover > span{
background: transparent url(http://dl.getdropbox.com/u/228089/action-button-left-hover.png) no-repeat;
color: white;
}
And as I said in the comment above try to avoid to use separate images for your button states.
Use only one image and for ex. on hover just 'change' the background-position to the part of image representing the state you want!
It will save you the "button disappearance" until the new image is loaded.
You could change the hover rule to only be for a.action-button At present you have the style rule for both a.action-button and its span.
a.action-button:hover { ...
and
a.action-button span:hover { ....
Instead try applying it this way:
a.action-button:hover { ...
and
a.action-button:hover span { ...
won't work on some older version of IE however.
http://jsfiddle.net/HZpDL/
Brain freeze here.
What I want to do is have the Suckerfish drop down menu link to be active on the current page in the drop down as well as the top item.
I.e. below, in the Articles menu item, I'd like to have the top item "Articles" active at the same time that either Categoryone or Categorytwo is active. (Archives is a single level menu item, included here just FYI.)
I have php set up to generate a body tag with the title of the page, so the body tag for the page Categoryone is <body id="Categoryone">
HTML:
<ul class="sf-menu">
<li id="Archives-menu" class="current">Archives</li>
<li id="Articles">Articles<ul>
<li id="Categoryone-menu" class="current">Categoryone</li>
<li id="Categorytwo-menu" class="current">Categorytwo</li></ul></li>
</ul>
CSS:
#Archives #Archives-menu a, #Categoryone-menu #Categoryone-menu a, #Categorytwo-menu #Categorytwo-menu a
{
color:#fff;
}
If I throw this in #Articles #Articles-menu a to try and make Articles active, then all the links in the drop down are active.
You have not given much info about that you are truing to do. But here is my guess: Your selector is off. Try this:
#Archives a , #Archives-menu a , .current
{
color:#fff;
}
Also remove the current class from those items and add it to the appropriate item dynamically when the user is on the right page. (Maybe Sukerfish does that for you?)