是否可以根据屏幕宽度更改 Bootstrap 弹出窗口的操作?
我问这个问题 关于根据屏幕大小更改引导程序弹出窗口的位置。
答案很好 - 但我现在也想更改弹出窗口的操作(因此在移动设备上单击即可)以及位置,并且我在重构代码时遇到了困难。这就是我所拥有的:
$(document).ready(function(){
$('#my_list li').popover({
placement: wheretoplace
});
});
function wheretoplace(){
var width = window.innerWidth;
if (width<500) return 'below';
return 'left';
}
如何修改 wheretoplace
函数以返回两个内容:placement
值和 trigger
值?我已经在 jsFiddle 中找到了现有的东西。
编辑 - 我修改了上面的 jsFiddle 以显示完整的解决方案,在下面的 @James 答案中添加了 click
事件。
I asked this question regarding changing the position of a bootstrap popover depending on the size of the screen.
The answer was great - however I also now want to change the action for popovers (so it's on click for mobile) as well as the location, and am having difficulty re-factoring the code. This is what I have:
$(document).ready(function(){
$('#my_list li').popover({
placement: wheretoplace
});
});
function wheretoplace(){
var width = window.innerWidth;
if (width<500) return 'below';
return 'left';
}
How would I amend the wheretoplace
function to return two things: the placement
value along with a trigger
value? I've got the existing stuff in a jsFiddle.
Edit - I've amended my jsFiddle above to show the complete solution, adding a click
event to @James' answer below.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您尝试从函数返回两个值,请尝试将它们分配为对象的属性,然后返回该对象。
例如。
然后在调用
wheretoplace
的函数中:这是您想要做的吗?
编辑:响应下面的评论:
与 jsFiddle 演示 一样,
通过将触发器分配为“手动”文档准备就绪后,您就可以在点击处理程序中调用
$(element).popover("toggle")
来切换弹出窗口的外观。If you are trying to return two values from the function, try assigning them as properties of an object and then return that object.
eg.
Then in the function calling
wheretoplace
:Is this what you are trying to do?
EDIT: In Response to the comment below:
As with the jsFiddle demo
By assigning the trigger as "manual" on document ready, you are then able to call
$(element).popover("toggle")
in a click handler which will toggle the appearance of the popover.