如何将DIV放置在浏览器的中心

Neeraj

我正在开发移动应用程序。我有饼图和条形图,如何在浏览器窗口的中心放置固定大小的DIV。如果调整了浏览器的大小,我希望DIV调整其位置。我尝试过的 实际上是它的“ R图”

<div id="output" ><canvas id="cvs" width="350" height="350" >[No canvas support]</canvas></div>

<script>
$(document).ready(function ()
    {
        var pie = new RGraph.Pie('cvs', [45,20,25,10])
            .set('colors', ['#F00', '#F00','#666','#ccc'])
            .set('events.click', myEventListener)
            .set('events.mousemove', function (e, piechart) {e.target.style.cursor = 'pointer';})
            .set('title.y', 30)
            .set('key', ['sunday','monday','tuesday','wednesday'])
            .set('key.colors', ['#f00', '#f00','#666','#ccc'])
            .set('key.interactive', true)
            .set('key.position', 'gutter')
            .set('gutter.left', 45)
            .set('key.position.y', 315)
            .set('key.rounded', false)
            .set('radius', 100)
            .set('linewidth', 1)
            .draw();
    })
</script>

<style>
#output {
width: 350px;
height: 350px;
background-color: none;
position: absolute;
top:0;
bottom: 40%;
left: 0;
right: 0;
margin: auto;
}

</style>
Gajotres

工作示例:http : //jsfiddle.net/Gajotres/8kXWV/

HTML:

<div data-role="page" id="index">
    <div data-theme="b" data-role="header">
        <h1>Index page</h1>
    </div>

    <div data-role="content">
        <img src="http://images5.fanpop.com/image/photos/29500000/GamesRadar-Puppy-puppies-29566786-200-200.jpg" alt="image"/>
    </div>
</div>    

的JavaScript

function center(){
    w=$(window).width();
    h=$(window).height();

    img_w=$('img').width();
    img_h=$('img').height();

    pos_top=(h-img_h)/2; 
    pos_left=(w-img_w)/2;

    $('img').css({'top':pos_top,'left':pos_left+'px', position: "absolute"});
}

$(document).on('pageshow', '#index', function(){ center(); });
$( window ).on( "orientationchange resize", function( event ) {
    center();
});

的CSS

.ui-content {
    position:absolute;
    top:40px;
    right:0;
    bottom:0;
    left:0;
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

(CSS)如何将Div放置在浏览器右下角附近,相对于浏览器大小?

调整浏览器的宽度大小后,如何将3个div放置在一列中?

如何将浏览器插件提交给软件中心

调整浏览器屏幕大小时,如何将图像放置在段落下方?

如何将GWT对话框放置在浏览器的右下角?

如何将子div垂直放置在父div的中心?

如何将表格水平和垂直放置在div的中心

CSS:如何将div以动态宽度放置在中心

当图像不在中心容器中时,如何将元素从其容器中拉出到浏览器的左侧或右侧

如何将main div扩展到整个浏览器窗口高度?

如何将谷歌浏览器中的默认浏览器搜索更改为实际的谷歌浏览器?

将div滚动到浏览器顶部时,如何将div设置为position:fixed?

如何将检查的浏览器元素设置为此

如何将Chromium浏览器数据导入Chrome

如何将交互的 IE 浏览器带到前台?

如何将浏览器参数传递给Watir

如何将gridView放置在屏幕中心

当浏览器窗口小于div大小时,如何保持div中心?

如何将我的 svg 图像定位到浏览器的中心

悬停在上方时如何将放大的div放置在中心?

如何将Google Chrome浏览器作为两个唯一的Google Chrome浏览器运行?

将三个div并排放置,但左和右div必须重复到浏览器的边缘

浏览器如何将相邻的div布局为浮动div

如何将VSCode调试器附加到Brave浏览器?

如何将捕获的照片(从浏览器-画布)上传到节点服务器?

如何将文本从Vim编辑器粘贴到浏览器?

浏览器如何将Cookie与其发送Cookie的服务器相关联?

如何禁用Web浏览器中的自动光标放置?

如何将桌面图标标题放置在中心?