简体   繁体   English

CSS hover 上的 div 仅过渡到部分 div?

[英]CSS transition of div on hover over only part of div?

Let me see how well I can explain this.让我看看我能解释多好。 I am working on an index on a website that is in a div that is pushed off of the page via css margin with only part of it showing.我正在一个网站上的一个索引上工作,该网站位于一个 div 中,该 div 通过 css 边距被推离页面,仅显示部分内容。 When you hover over the part that is showing, the rest slides down into view.当您将 hover 滑过显示的部分时,rest 会向下滑动到视图中。 This works fine.这很好用。 I already have the transition effect in place for the margin change slide and also a background color change with rgba.我已经为边距更改幻灯片设置了过渡效果,还使用 rgba 更改了背景颜色。 It looks very nice.看起来很不错。

My question is, the index is around 500px wide and the visible part before hovering is 70px high.我的问题是,索引大约有 500 像素宽,悬停前的可见部分高 70 像素。 So that is a fairly large area of the screen for people to accidentally catch with their mouse hover if they are not trying to display the index div.所以这是一个相当大的屏幕区域,如果他们不尝试显示索引 div,人们可能会不小心用鼠标抓住 hover。 Is there some way that I can only make part of the initially visible portion of the div activate the hover transition animation to bring the full div into view?有什么方法可以让 div 的最初可见部分激活 hover 转换 animation 以使整个 div 可见吗? Or perhaps someway I can attach a smaller div to this one as a sort of tab, that will bring down the larger div and itself via transition on hover?或者也许我可以将一个较小的 div 作为一种选项卡附加到这个 div,这将通过 hover 上的转换降低较大的 div 和它本身?

I hope this makes sense.我希望这是有道理的。 Thank you.谢谢你。

Here is the basic idea of the current code:这是当前代码的基本思想:

#index {
    position:fixed;
    background:rgba(0,0,0,0.3);
    width:500px;
    height:500px;
    top:0;
    left:50%;
    margin:-430px 0 0 -500px;
    transition:0.5s;
    -moz-transition:0.5s;
    -webkit-transition:0.5s;
    -o-transition:0.5s;}

#index:hover {
    background:rgba(0,0,0,0.8);
    margin:0 0 0 -500px;}

jsFiddle: 的jsfiddle:

http://jsfiddle.net/wZ8zX/1/ http://jsfiddle.net/wZ8zX/1/

html: HTML:

<div id="slider"><div id="trigger"><br></div></div>

js: JS:

$('#trigger').hover(function(){
    $(this).parent().animate({'top':0},500); 
});
$('#slider').mouseleave(function(){
    $(this).animate({'top':-150},500); 
});

solution without jQuery: 没有jQuery的解决方案:
http://jsfiddle.net/wZ8zX/3/ http://jsfiddle.net/wZ8zX/3/

sorry i usually just browse jquery questions, so i didn't check the tags lol 对不起,我通常只是浏览jquery问题,所以我没有检查标签大声笑

Using only CSS you can use another block, or a pseudo-element to overlay the parts of block where you don't want to have transition, and then, after hover, make z-index for the element with transition bigger than overlaying element, so all the contents of it would be accessible. 仅使用CSS,您可以使用另一个块或伪元素来覆盖您不希望转换的块的部分,然后,在悬停之后,为过渡大于重叠元素的元素创建z-index,所以它的所有内容都是可以访问的。

Here is a fiddle with an example: http://jsfiddle.net/kizu/Y3px6/1/ 这是一个例子的小提琴: http//jsfiddle.net/kizu/Y3px6/1/

This comes from the position:relative property.这来自 position:relative 属性。 I strongly feel that your current div tag has position relative property.我强烈认为您当前的 div 标签具有 position 相关属性。 Please remove that.请删除它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM