angularjs - 查看端口根据用户选择调整大小

标签 angularjs html css

基本上我有一个基于 bootstrap 3 的 Angular 元素,用于调整媒体查询的大小。

我打算做的是允许用户在桌面模式(笔记本电脑全屏宽度)或移动模式(媒体宽度 < 667px)之间切换。

我看到很多主题预览网站都有这个功能。由于这是一个很常见的功能,我希望可以通过这种方式完成,但不确定如何准确实现。

注意:我不希望更改现有 CSS 的任何部分。

我对如何实现这一点的看法。

<html ng-viewport="deviceWidth">
    <button ng-click="changeDeviceWidth()">
</html>

// initial
$scope.deviceWidth = getDeviceWidthFunction();
$scope.changeDeviceWidth = function (deviceWidth) {
    $scope.deviceWidth = deviceWidth;
}

最佳答案

首先:给你视口(viewport)元 id

    <meta id="viewport" name="viewport" content="width=device-width, initial-scale=1">

第二:创建选择器按钮

    <div id="selecter">
    <button onclick="toDesktop()"> Desktop</button>
    <button onclick="toTablet()"> Tablet</button>
    <button onclick="toMobile()"> Mobile</button>
    </div>

第三:添加iframe作为内容查看器

            <iframe id="mycontent" src="http://www.majali.net"></iframe>

第四:添加JS函数设置视口(viewport)、内容宽高

         <script>
            function toDesktop() {
                document.getElementById("viewport").setAttribute("content", "width=1200");
                document.getElementById("mycontent").style.width='100%';
                document.getElementById("mycontent").style.height='600px';                  
            }

            function toMobile() {
                document.getElementById("viewport").setAttribute("content", "width=340");
                document.getElementById("mycontent").style.width='320px';
                document.getElementById("mycontent").style.height='480px';
            }       

            function toTablet() {
                document.getElementById("viewport").setAttribute("content", "width=767");
                document.getElementById("mycontent").style.width='767px';
                document.getElementById("mycontent").style.height='600px';
            }                           
        </script>

关于angularjs - 查看端口根据用户选择调整大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39803165/

相关文章:

c# - 单击按钮时弹出窗口关闭并重定向到不同页面!

javascript - $timeout 是避免 AngularJS 指令中 jQuery 插件呈现问题的唯一/推荐方法吗?

angularjs - 如何在 AngularJS 指令中使用定义的文本/ng-模板

html - <按钮> 在 IE8 中不工作

html - 如何使用具有不同文件结构的 Dart Polymer?

javascript - 带有旋转 Logo 的整页滚动

css - 页面在 Safari 中上移,但在其他浏览器中没有

html - 在 float div 中以百分比形式包裹高度的图像

javascript - 在 Angular 中使用没有路由的 Controller

javascript - 如何自动关闭 JHipster 上的警报?