首页 \ 问答 \ 如何让Bootstrap 3在下拉列表中下推页面内容(How to get Bootstrap 3 to push down page content on dropdown click)

如何让Bootstrap 3在下拉列表中下推页面内容(How to get Bootstrap 3 to push down page content on dropdown click)

Google AdSense禁止网站使用任何元素覆盖广告 - 甚至是扩展的下拉菜单 - 所以我正在寻找一种方法来告诉Bootstrap在点击下拉菜单时压下页面内容,因此排行榜被推倒掩盖。

我查看了stackoverflow,到目前为止我能找到的所有问题都是询问如何叠加内容而不是将其推下来。 我想反过来(我认为这必须随着Bootstrap 3而改变)。

我知道这是可能的,因为在网站的响应版本上,右上角的切换按下了页面内容,我想要下拉菜单:

http://getbootstrap.com/examples/navbar/

(打开此链接并缩小浏览器窗口,然后单击右上角的三行)。

如果菜单未折叠,如何将该功能添加到下拉项?

谢谢!


编辑:

这是我为了解决基于@ hsb1007的响应的解决方案而添加的jQuery:

$('.class-name-1').on('show.bs.dropdown', function () {
     $('.leaderboard').css('margin-top', 450);       
})
$('.class-name-2').on('show.bs.dropdown', function () {
     $('.leaderboard').css('margin-top', 200);       
})
$('.dropdown').on('hide.bs.dropdown', function () {
     $('.leaderboard').css('margin-top', 0);         
})

Google AdSense prohibits websites from covering up ads with any element - even an expanded dropdown menu - so I am looking for a way to tell Bootstrap to push down the content of the page when a dropdown menu is clicked, so the leaderboard is pushed down instead of covered up.

I have looked on stackoverflow, and all of the questions I can find so far are asking how to overlay content and not push it down. I would like to do the inverse (I think this must have changed with Bootstrap 3).

I know this is possible, because on the responsive version of a site the toggle on the top right pushes down the page content, exactly I would like the dropdown menus to do:

http://getbootstrap.com/examples/navbar/

(open this link and shrink your browser window, then click the three lines in the top right).

How can I add that functionality to dropdown items when the menu is not collapsed?

Thank you!


EDIT:

Here is the jQuery I added to solve the solution based on @hsb1007's response:

$('.class-name-1').on('show.bs.dropdown', function () {
     $('.leaderboard').css('margin-top', 450);       
})
$('.class-name-2').on('show.bs.dropdown', function () {
     $('.leaderboard').css('margin-top', 200);       
})
$('.dropdown').on('hide.bs.dropdown', function () {
     $('.leaderboard').css('margin-top', 0);         
})

原文:https://stackoverflow.com/questions/20669714
更新时间:2023-06-17 16:06

最满意答案

最后更新

自Express 4.10以来,该框架支持多视图文件夹功能

只需将位置数组传递给views属性即可。

app.set('views', [__dirname + '/viewsFolder1', __dirname + '/viewsFolder2']);

Express 2.0

据我所知,express现在不支持多个视图路径或名称空间(就像静态中间件一样)

但是,您可以自己修改查找逻辑,以便按照您希望的方式工作,例如:

function enableMultipleViewFolders(express) {
    // proxy function to the default view lookup
    var lookupProxy = express.view.lookup;

    express.view.lookup = function (view, options) {
        if (options.root instanceof Array) {
            // clones the options object
            var opts = {};
            for (var key in options) opts[key] = options[key];

            // loops through the paths and tries to match the view
            var matchedView = null,
                roots = opts.root;
            for (var i=0; i<roots.length; i++) {
                opts.root = roots[i];
                matchedView = lookupProxy.call(this, view, opts);
                if (matchedView.exists) break;
            }
            return matchedView;
        }

        return lookupProxy.call(express.view, view, options)
    };
}

您将通过调用上述函数并将express作为参数传递来启用新逻辑,然后您将能够为配置指定一个视图数组:

var express = require('express');
enableMultipleViewFolders(express);
app.set('views', [__dirname + '/viewsFolder1', __dirname + '/viewsFolder2']);

或者,如果您愿意,可以直接修补框架(更新其中的view.js文件)

这应该在Express 2.x中工作 ,不知道它是否会使用新版本(3.x)

UPDATE

不幸的是,上述解决方案在Express 3.x中不起作用,因为express.view将是未定义的

另一个可能的解决方案是代理response.render函数并设置views文件夹配置直到获得匹配:

var renderProxy = express.response.render;
express.render = function(){
    app.set('views', 'path/to/custom/views');
    try {
        return renderProxy.apply(this, arguments);
    }
    catch (e) {}
    app.set('views', 'path/to/default/views');       
    return renderProxy.apply(this, arguments);
};

我没有对它进行测试,无论如何,这对我来说都很难受,不幸的是,这个功能又被推回去了: https//github.com/visionmedia/express/pull/1186

更新2

Express 4.10中添加了此功能,因为已将以下拉取请求合并: https//github.com/strongloop/express/pull/2320


Last Update

The multiple view folders feature is supported by the framework since Express 4.10

Just pass an array of locations to the views property, like so.

app.set('views', [__dirname + '/viewsFolder1', __dirname + '/viewsFolder2']);

Express 2.0

As far as I know express doesn't support multiple view paths or namespaces at the moment (like the static middleware do)

But you can modify the lookup logic yourself so that it works the way you want, for example:

function enableMultipleViewFolders(express) {
    // proxy function to the default view lookup
    var lookupProxy = express.view.lookup;

    express.view.lookup = function (view, options) {
        if (options.root instanceof Array) {
            // clones the options object
            var opts = {};
            for (var key in options) opts[key] = options[key];

            // loops through the paths and tries to match the view
            var matchedView = null,
                roots = opts.root;
            for (var i=0; i<roots.length; i++) {
                opts.root = roots[i];
                matchedView = lookupProxy.call(this, view, opts);
                if (matchedView.exists) break;
            }
            return matchedView;
        }

        return lookupProxy.call(express.view, view, options)
    };
}

You will enable the new logic by calling the function above and passing express as a parameter, and then you will be able to specify an array of views to the configuration:

var express = require('express');
enableMultipleViewFolders(express);
app.set('views', [__dirname + '/viewsFolder1', __dirname + '/viewsFolder2']);

Or, if you prefer, you can patch the framework directly (updating the view.js file inside it)

This should work in Express 2.x, not sure if it will with the new version (3.x)

UPDATE

Unluckily the above solution won't work in Express 3.x since express.view would be undefined

Another possible solution will be to proxy the response.render function and set the views folder config until it gets a match:

var renderProxy = express.response.render;
express.render = function(){
    app.set('views', 'path/to/custom/views');
    try {
        return renderProxy.apply(this, arguments);
    }
    catch (e) {}
    app.set('views', 'path/to/default/views');       
    return renderProxy.apply(this, arguments);
};

I've not tested it, it feels very hacky to me anyway, unluckily this feature has been pushed back again: https://github.com/visionmedia/express/pull/1186

UPDATE 2

This feature has been added in Express 4.10, since the following pull request has been merged: https://github.com/strongloop/express/pull/2320

相关问答

更多
  • 最后更新 自Express 4.10以来,该框架支持多视图文件夹功能 只需将位置数组传递给views属性即可。 app.set('views', [__dirname + '/viewsFolder1', __dirname + '/viewsFolder2']); Express 2.0 据我所知,express现在不支持多个视图路径或名称空间(就像静态中间件一样) 但是,您可以自己修改查找逻辑,以便按照您希望的方式工作,例如: function enableMultipleViewFolders(ex ...
  • 据此,在设置状态代码之前调用respond方法#2的问题。 这有效: get('/2', function () { var myRequest = this; function up(s) { myRequest.halt(200, s.toUpperCase()); } return posix.cat('/etc/motd').addCallback(up); }); According to this, the problem with approa ...
  • 得到这条线 var models = require('./models') 你需要创建./models/index.js文件,其中包含以下内容: module.exports = { // your model's code }; 你可以在这里阅读更多 to get this line var models = require('./models') working you need to create ./models/index.js file with following content: m ...
  • 根据您的快速静态配置和您的路由配置,express期望在views目录中的index.html , resume.html和contact.html 。 默认情况下,表达式res.render()方法需要您在./views文件夹中的./views : http : ./views 所以你的项目应如下所示: www |-- views | |-- index.html | |-- resume.html | +-- contact.html |-- node_modules | + ...
  • 你没有调用app.listen()函数。 您应该调用Express函数而不是http.createServer 。 请看一个基本的例子 。 相关代码: app.listen(3000, function () { console.log('Example app listening on port 3000!'); }); 编辑:正如slebetman在评论中写道的那样,更普遍的方式是: http.createServer(app).listen(port, function(){ cons ...
  • 你的中间件顺序错误。 Express按顺序宣布它们。 将你的app.post('/admin...行app.post('/admin...你的Not Found中间件上面。 You have your middleware in the wrong order. Express prossess them in order declared. Move your app.post('/admin... line ABOVE your Not Found middleware.
  • 我将p更改为ul(p标签不应该有子项)。 我在jade中定义了users数组(适用于测试)。 注意- each和li=之后的缩进。 - users = [ { name:'Duncan' }, { name: 'Henry'}, { name: 'Raynos' } ] h1 Users ul#users - each user in users li= user.name I changed the p to a ul (p tags shouldn't have children). A ...
  • JSHTML目前适用于Express.js 2.有计划让引擎与Express.js 3一起使用,但目前我忙于享受夏天! 期待在冬天解决这个问题! JSHTML currently works with Express.js 2. There are plans on getting the engine to work with Express.js 3, but currently I am too busy with enjoying the summer! Expect a fix for this ...
  • 您可以运行这两个框架,但是每个框架都绑定到一个侦听特定端口的http或https服务器,并且因为它们使用相同的协议,所以您将遇到问题。 所以你可以做的是在端口80或443上运行你的快速服务器,然后在端口8000上用节点运行你的API服务器。然后将流量转发到从快递到节点的api路径(简称website.com:8000)。 You can run both frameworks however each framework is bound to an http or https server that li ...
  • 几乎可以肯定, app.all路由正在发送回应该发送javascript的请求的HTML。 您需要查看浏览器作为脚本标记获取的特定URL,但服务器正在发回HTML。 相应的.js文件可能不在public/js ,导致路由器进入catch-all路由。 请注意,由于URL与文件系统结构的express.static您可以将express.static路由压缩为此。 // serve all asset files from necessary directories app.use(express.stati ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)