简体   繁体   English

中心和中间位置,与窗口滚动无关

[英]Center & middle positioning regardless of window scroll

I'm using the 'read more' buttons on this page to display previously (display:none) divs: http://apexhubmobile.co.uk/corporate-friends 我正在使用此页面上的“阅读更多”按钮来先前显示(显示:无)div: http : //apexhubmobile.co.uk/corporate-friends

The problem is when they display they force the window to the top of the page to view it, I tried changing the positioning to fixed and the box then didn't display properly until I scrolled a little. 问题是当他们显示时,他们迫使窗口移至页面顶部以进行查看,我尝试将位置更改为“固定”,然后直到我稍微滚动一下才能正确显示该框。

My aim is for the hidden div to show up in the center & middle of the window regardless of how far down the page the user is. 我的目标是使隐藏的div出现在窗口的中心和中间,而不管用户的页面有多远。 Here's a few excerpts of code. 这是一些代码摘录。

<style>
.b1 {float:left;width:292px;background-color:#F2F2F2;margin:0 4px 5px;vertical-align:middle;border:1px solid grey;line-height:0 !important;}
.b2 {line-height:0 !important;}
.f1 {z-index:999;background-color:white;border:1px solid; grey; position:fixed; top:50%; left:50%; height:430px; width:900px; margin:-215px 0 0 -450px; display:none;}
.f2 {width:100%;background-color:silver;text-align:center; font-size:1.2em; color:white;}
.f3 {position:absolute; right: 0;top: 2px; font-size:0.8em;color:black;}
.f4 {width:35%; height:410px; float:left; display:inline-block;padding:15px 0 0 15px;text-align:center;}
.f5 {width:35%;float:left;text-align:center;position:absolute;bottom:15px;}
.f6 {width:65%;float:left;display:inline-block;padding:15px;}

<div id="s38" class="f1"><div class="f2">SEMINARS@THIRTYEIGHT
<span class="f3">&nbsp;&#91; <a href="#" onclick="jQuery('#s38').css('display', 'none');">close</a> &#93;&nbsp;</span></div><div class="f4">
 <img src="http://apexhubmobile.co.uk/images/friends/Seminars38.png">
 <div class="f5"><a href="http://seminarsthirtyeight.com" target="new">www.seminarsthirtyeight.com</a></div></div><div class="f6">
Seminars@thirtyeight is a centre for continuing professional development for the whole dental team. Our practice and seminar facility are intimate and inspirational. They are the ‘first class’ end of dental education and mentoring. All of the courses are GDC verifiable.

Held within private dental practice 38 Devonshire Street, located in the heart of London’s Harley Street medical district, the aim at Seminars@thirtyeight is to give you an unsurpassed dental training experience, with some of the world’s most gifted dental mentors. Their relaxed and intimate venue ensures you the best opportunity to network at a professional level and meet the top researchers, opinion leaders and coaches within the dental industry.

 <div class="b1"><img src="http://apexhubmobile.co.uk/images/friends/16.png"><div class="b2"><a href="#" onclick="jQuery('#s38').css('display', 'initial');"><img src="http://apexhubmobile.co.uk/test/rm.png" onMouseOver="this.src='http://apexhubmobile.co.uk/test/rmy.png'" onMouseOut="this.src='http://apexhubmobile.co.uk/test/rm.png'"></a></div></div>

Any ideas? 有任何想法吗?

Your problem is that you set attribute "href='#'" so it try to target # anchor when you click on it, but as it is not found, it just set the scroll to the top. 您的问题是您设置了属性“ href ='#'”,因此当您单击它时它会尝试定位#锚,但是由于找不到,它只是将滚动条设置到顶部。

You can remove href attributes and style in CSS cursor pointer for your links. 您可以在CSS光标指针中删除链接的href属性和样式。

Or set anchors onto your page. 或在页面上设置锚点。

PS : or maybe use event.preventDefault(); PS:或者可以使用event.preventDefault(); with jQuery 与jQuery

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

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