代码区项目交易流程

different div transition/show when hovering over left or right side


I'm wondering if anyone has an example to have a div that is hovered on the left side to show divone divtwo divthree and divfour, however when hovered on the right show divfive divsix divseven and diveight instead. I'd like it to look like this when either side is hovered over: http://i.imgur.com/T4leQWE.png

But, right side and left side should show different contents. When neither side is being hovered over, show nothing.

Also, here's the catch... The divs have to be repeatable, and will share unique names multiple times on the page, as this is for an account informational panel. there can be up to 10 on the same page

Problem courtesy of: askhir

Solution

HTML - wrapper div has unique name. Child divs have a right or left class name

<div id="containerOne"> <div class="left" style="display:none;">Left Side 1</div> <div class="left" style="display:none;">Left Side 2</div> <div class="left" style="display:none;">Left Side 3</div> <div class="right" style="display:none;">Right Side 1</div> <div class="right" style="display:none;">Right Side 2</div> <div class="right" style="display:none;">Right Side 3</div> </div>

CSS - Wrapper div appears as box, child divs styles float, or could just right and align text in 100% div width

#containerOne { margin: 0 0 0 30px; width: 250px; height: 200px; border: 1px solid #333; } .left{ float:left; width:100%; text-align:left; } .right{ float:right; width:100%; text-align:right; }

script to determine which side this mouse is one, and then set style based on which side mouse is on, on mouse leave display = none for all child divs

function UpdateStyle(cls, style){ var left_ele = document.getElementsByClassName(cls); for (var i = 0; i < left_ele.length; ++i) { var item = left_ele[i]; item.style.display = style; } } $("#containerOne").on('mousemove', function(e) { var mouseSide; if ((e.pageX - this.offsetLeft) < $(this).width() / 2) { UpdateStyle('left','block'); UpdateStyle('right','none'); } else { UpdateStyle('left','none'); UpdateStyle('right','block'); } }).on('mouseout', function(){ UpdateStyle('left','none'); UpdateStyle('right','none'); });

Solution courtesy of: Jason Montgomery

Discussion

Have a look on this EXAMPLE

It is not exactly what you are looking for but you can get based on this to customize it and achieve what you need.

I am using the jQuery

$("#selector").on( { mouseenter: function() { $("#toggle").show('slide', { direction: 'left' }, 1000); }, mouseleave: function() { $("#toggle").hide('slide', { direction: 'left' }, 1000); } });

Hope this helps

Discussion courtesy of: Thanos

This recipe can be found in it's original form on Stack Over Flow .

本文前端(javascript)相关术语:javascript是什么意思 javascript下载 javascript权威指南 javascript基础教程 javascript 正则表达式 javascript设计模式 javascript高级程序设计 精通javascript javascript教程

点击收藏

LAST How do JavaScript arrays work under the hood? JavaScript Console Tips &amp; Tricks NEXT