View and Data API Tips: Constrain Viewer Within a div Container

时间:2022-11-08 14:16:51

By Daniel Du

When working with View and Data API, you probably want to contain viewer into a <div> tag, the position and size of <div> can be defined with CSS. The HTML can be simple as below, a <div> tag as a container, the position and style is defined in a CSS class named as “viewer”:

    <h2>Autodesk View and Data API</h2>
<div id="viewer" class="viewer"> </div>

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

For example, here is my css class, make the viewer container with 800px * 500px, and to make it easy to see, I also add a background color:

.viewer {

    background-color: darksalmon;
height: 500px;
width: 800px;
}

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

Here is how it looks like, seems good:

View and Data API Tips: Constrain Viewer Within a div Container

Now let’s add viewer, the code snippet is simple, you can go to github for complete code:

        var viewerContainer = document.getElementById(containerId);
var viewer = new Autodesk.Viewing.Private.GuiViewer3D(
viewerContainer);

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

But just with this style, the viewer is “overflow” out of the <div> container,:

View and Data API Tips: Constrain Viewer Within a div Container

Here is a tip to contains the viewer into the <div> container, just edit the CSS as below, add “position : relative” :

.viewer {

    background-color: darksalmon;
height: 500px;
width: 800px;
position: relative;
}

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

Here is how it looks after the change, the viewer is constrained within the div tag:

View and Data API Tips: Constrain Viewer Within a div Container

Not a big deal, just a small tip in case you do not know.

View and Data API Tips: Constrain Viewer Within a div Container的更多相关文章

  1. View and Data API Tips&colon; Hide elements in viewer completely

    By Daniel Du With View and Data API, you can hide some elements in viewer by calling "viewer.hi ...

  2. View and Data API Tips&colon; how to make viewer full screen

    By Daniel Du If you have not heard of View and Data API, here is the idea, the View & Data API e ...

  3. View and Data API tips&colon; 缓存Access Token

    对于云API服务,常见的方式就是按照API调用次数收费,某些API调用也就有某些限制,比如在特定时间内只允许调用指定的次数以免造成滥用.虽然Autodesk的view and Data API目前还没 ...

  4. View and Data API Tips &colon; Conversion between DbId and node

    By Daniel Du In View and Data client side API, The assets in the Autodesk Viewer have an object tree ...

  5. Autodesk View and Data API二次开发学习指南

    什么是View and Data API? 使用View and Data API,你可以轻松的在网页上显示大型三维模型或者二维图纸而不需要安装任何插件.通过View and Data API,你可以 ...

  6. Using View and Data API with Meteor

    By Daniel Du I have been studying Meteor these days, and find that Meteor is really a mind-blowing f ...

  7. 使用AxisHelper帮助理解View and Data API中的坐标系统

    大家使用View and Data API做三维模型开发,必然首先要理解View and Data API的坐标系统,即XYZ三个轴向分别是怎么定义的.Three.js里面提供了一个AxisHelpe ...

  8. 在View and Data API中更改指定元素的颜色

    大家在使用View and Data API开发过程中,经常会用到的就是改变某些元素的颜色已区别显示.比如根据某些属性做不同颜色的专题显示,或者用不同颜色表示施工进度,或者只是简单的以颜色变化来提醒用 ...

  9. 特大喜讯,View and Data API 现在支持中文界面了

    大家经常会问到,使用View and Data API怎么做界面的本地化,来显示中文,现在好消息来了,从v1.2.19起,View and Data API开始支持多国语言界面了.你需要制定版本号为v ...

随机推荐

  1. PHP--冒泡、选择、插入排序法

    使用php来实现常用三种排序方法: 冒泡.选择.插入中,最优的是插入排序,我就把插入排序的流程画下来了: 插入排序法的流程图: 插入排序的代码: function InsertSort(&$a ...

  2. HDU 4597 Play Game

    题目链接 什么都不想说,最近状态暴跌.. #include <cstdio> #include <cstring> #include <iostream> usin ...

  3. lib和dll的例子

    .dll和.lib的区别 lib是静态库,dll一般是动态链接库(也有可能是别的)比如要编译个exe,lib在编译的时候就会被编译到exe里,作为程序的一部分而dll是不被编译进去,是运行的时候才调入 ...

  4. jQuery制作go to top按钮

    转自:http://www.w3cplus.com/jquery/scrolling-to-the-top-with-jquery 每每看到网友Blog的页面底部或中间有一个按钮回到页面顶部,羡慕死人 ...

  5. 反转int型数字

    如 321 反转 123 120 反转21 注意处理最后的零,以及负数情况 ,最后就是溢出情况了 /** * @param {number} x * @return {number} */ var r ...

  6. 关于安装linux时要怎么分区的考虑的參考方式&quest;

    对于使用最小化安装的centos7文件夹列表,注意链接方式的文件夹会在统计占用空间时不会算入的; watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcWlkaX ...

  7. 02月刊(上) &vert; 微信小程序

    * { margin: 0; padding: 0 } .con { width: 802px; margin: 0 auto; text-align: center; position: inher ...

  8. css相关tips

    12px的中文占据16px高度,英文占据14px的高度.所以做双语版网页时css样式要做相应调整. IE10,IE11浏览器当点击input text文本框时,输入文本后出现一个删除功能的X按钮. 去 ...

  9. SUM游戏

    题意:就是有一个长度为n的整数序列,两个游戏者A和B轮流取数,A先取.每次玩家只能从左端或者右端取任意数量个数,但不能两端都取. 所有数都被取走后游戏结束,然后统计每个人取走的所有数之和,作为各自的得 ...

  10. Javascript日期类型的妙用

    http://heeroluo.net/Article/Detail/110 获取某个月份的天数 相信大家读小学的时候就知道一年十二个月各有多少天了,这里面有个特殊的存在——2月.闰年的2月有29天, ...