未加星标

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

字体大小 | |
[前端(javascript) 所属分类 前端(javascript) | 发布者 店小二03 | 时间 2019 | 作者 红领巾 ] 0人收藏点击收藏

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教程

分页:12
转载请注明
本文标题:different div transition/show when hovering over left or right side
本站链接:https://www.codesec.net/view/628299.html


1.凡CodeSecTeam转载的文章,均出自其它媒体或其他官网介绍,目的在于传递更多的信息,并不代表本站赞同其观点和其真实性负责;
2.转载的文章仅代表原创作者观点,与本站无关。其原创性以及文中陈述文字和内容未经本站证实,本站对该文以及其中全部或者部分内容、文字的真实性、完整性、及时性,不作出任何保证或承若;
3.如本站转载稿涉及版权等问题,请作者及时联系本站,我们会及时处理。
登录后可拥有收藏文章、关注作者等权限...
技术大类 技术大类 | 前端(javascript) | 评论(0) | 阅读(24)