如何让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
最满意答案
最后更新
自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 ...
-
如何从node.js表达动作处理程序执行延迟响应?(How do I do a deferred response from a node.js express action handler?)[2023-11-17]
据此,在设置状态代码之前调用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 ...
-
用Node.JS表达JS(Express JS with Node.JS)[2022-12-16]
根据您的快速静态配置和您的路由配置,express期望在views目录中的index.html , resume.html和contact.html 。 默认情况下,表达式res.render()方法需要您在./views文件夹中的./views : http : ./views 所以你的项目应如下所示: www |-- views | |-- index.html | |-- resume.html | +-- contact.html |-- node_modules | + ... -
路由node.js和express(routing node.js and express)[2022-08-31]
你没有调用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 ... -
Node.js和Express;(Node.js and Express; POST 404)[2024-03-26]
你的中间件顺序错误。 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 ...
-
解决node.js错误(Troubleshooting node.js error)[2022-08-31]
几乎可以肯定, 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 ...