【问题标题】:How to show fixed div in middle of screen when screen show bottom of page屏幕显示页面底部时如何在屏幕中间显示固定的div
【发布时间】:2013-12-12 15:58:07
【问题描述】:

我设计了一个包含许多小图像的页面,我喜欢点击小图像然后打开一个固定的 div 并显示我的大图像,它非常适合页面顶部的图像,但是当滚动下拉到页面底部时,它现在是干得好,什么是truble,你可以在这个页面看到它:http://www.3dcreate.ir/New3DCreate/Pages/Gallery/3DGallery/3dg_Chosen.php

HTML 代码:

<!-- This is Div of Large Image and Background Shade -->
<div class="BackgroudShade"></div>
<div class="DivOfImage"><img class="LargeImage"/></div>

CSS 代码:

.DivOfImage {
    border: 8px solid #FFF;
    color:#FFF;
    background-color:#FFF;
    border-radius:10px;
    position:fixed;
}

JQuery 代码:

function LoadShowDiv () {
    $('.BackgroudShade').slideDown(800);   // shade of background will be visible
    $(".DivOfImage").show();               // Div of Large Image will be visible          
// When Image loaded successful then set width,height and top,left of Large Image Div 
// but i want set top,left when screen is scroll down to bottom of page
// then show Div at middle of screen in every time
    $('.LargeImage').load(function() {     
       $('.DivOfImage').width($('.LargeImage').width());
       $('.DivOfImage').height($('.LargeImage').height());
       var LeftPostion = (WidthOfScreen - $('.LargeImage').width()) / 2;
       var TopPostion = (HeightOfScreen - $('.LargeImage').height()) / 2;
       $(".DivOfImage").offset({ top: TopPostion, left: LeftPostion});
       $('.LargeImage').show(1000);
    })
}

$('#SmallImage').click(function(){
    $('.LargeImage').attr('src','LargeImage.jpg');
    LoadShowDiv();
})

【问题讨论】:

标签: javascript jquery css html absolute


【解决方案1】:

我不确定,但你为什么不试试:

$(".DivOfImage").css({'position': 'fixed', 'top': TopPostion + 'px', 'left': LeftPostion + 'px'});

而不是

$(".DivOfImage").offset({ top: TopPostion, left: LeftPostion});

【讨论】:

  • 谢谢我的朋友,我在jquery中删除了css代码并设置了DIV的css,它确实有效,谢谢
猜你喜欢
  • 1970-01-01
  • 2016-06-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-08-10
  • 2021-12-28
  • 1970-01-01
  • 2014-09-29
相关资源
最近更新 更多