-
Why if (//change b position) part write after (//show a list) part can’t work, have some error?
-
How can I make it so that when (.a-1).hover, (.b) not move and still in the same place after last change?
+0 can’t work?
jquery
//change b position
$(".a").hover(function(){
var newleft = $(".b").position().left + 200;
$(".b").css('left', newleft + 'px');
},function(){
var newleft = $(".b").position().left - 200;
$(".b").css('left', newleft + 'px');
});
$(".a-1").hover(function(){
var newleft = $(".b").position().left + 0;
$(".b").css('left', newleft + 'px');
},function(){
var newleft = $(".b").position().left + 0;
$(".b").css('left', newleft + 'px');
});
//show a list
$(".a").hover(function(){
$(".a-1, .a-2").show();
},function(){
$(".a-1, .a-2").hide();
});
$(".a-1").hover(function(){
$(".a-1, .a-2").show();
},function(){
$(".a-1, .a-2").hide();
});
$(".a-2").hover(function(){
$(".a-1, .a-2").show();
},function(){
$(".a-1, .a-2").hide();
});
html,css
<div class="a">a</div>
<div class="a-1">a-1</div>
<div class="a-2">a-2</div>
<div class="b">b</div>
.a{
position: absolute;
left: 100px;
top: 150px;
width: 105px;
background: red;
}
.a-1{
position: absolute;
left: 200px;
top: 150px;
width: 100px;
background: maroon;
display: none;
}
.a-2{
position: absolute;
left: 300px;
top: 150px;
width: 100px;
background: olive;
display: none;
}
.b{
position: absolute;
left: 200px;
top: 150px;
width: 100px;
background: blue;
}
I’ve modified your code a bit – http://jsfiddle.net/ga5Um/1/
(added a container div)
Is this a solution for you?