页面加载时的放大弹出菜单
Magnific Popup on Page Load
我正在尝试在页面加载时自动显示放大弹出菜单。
我有它,所以当我点击一个按钮时它就可以工作(这减少了一些可能的错误(,但我仍然无法让它在加载时出现。我试过这个和这个,但似乎都不起作用。
<script>
$('.open-popup-link').magnificPopup({
type:'inline',
midClick: true // Allow opening popup on middle mouse click. Always set it to true if you don't provide alternative source in href.
});
$.magnificPopup.open({
type: 'inline'
});
</script>
有人能帮我解决这个问题吗?理想情况下,它会在点击按钮时自动打开。
附加信息
这是工作按钮的html/erb:
<p><a href="#test-popup" class="open-popup-link btn btn-ghost hvr-grow" style="margin-top: 40px">Quick Man Check</a></p>
内容如下:
<div id="test-popup" class="white-popup mfp-hide">
<div class="">
<h1>Answer the following question to gain entry:</h1>
<% @random_partial = 'man_tests/test' + rand(0).round.to_s %>
<%= render partial: @random_partial %>
</div> <!-- hover-well -->
</div> <!-- white-popup mfp-hide -->
澄清:弹出窗口有一个表单数据的提交按钮,这会导致表单数据出现一次但只出现一次的问题。
更新:正如建议的那样,两者都是:
$.magnificPopup.open({
items: {
src: '#test-popup',
type: 'inline'
}
});
这个:
$('.open-popup-link').magnificPopup('open');
让它在加载时打开,但它会继续这样做,令人恶心,永远不允许查看索引页。
$.magnificPopup.open({
items: {
src: '#test-popup',
type: 'inline'
}
});
如果你能提供链接来检查问题,那就足够了。
试试下面的代码
<script>
function getPathFromUrl(url) {
return url.split(/[?#]/)[0];
}
if(getPathFromUrl(document.referrer) != getPathFromUrl(document.URL){
$.magnificPopup.open({
items: {
src: '#test-popup',
type: 'inline'
}
});
}
</script>
以下是基于时间的弹出的解决方案
var now, time, lastTimePopup, repeatAfter;
now = new Date();
time = now.getTime();
repeatAfter = 2 * 60 * 1000;//First number 2 is after number of minutes the popup should be showed.
if (localStorage.getItem('lastTimePopup') !== null) {
lastTimePopup = localStorage.getItem('lastTimePopup');
}
if (((now - lastTimePopup) >= repeatAfter) || !lastTimePopup) {
$.magnificPopup.open({
items: { src: '#test-popup' },
type: 'inline'
}, 0);
localStorage.setItem('lastTimePopup', now.getTime());
}
在文档中,我发现了以下内容:
// Open directly via API
$.magnificPopup.open({
items: {
src: '<div class="white-popup">Dynamically created popup</div>', // can be a HTML string, jQuery object, or CSS selector
type: 'inline'
}
});
您应该将其封装在$(document(.ready(function(({…}(;
我为您创建了一个Plunker工作样本:https://plnkr.co/edit/h1fmGbJg5cYONfwMQerF
另一种解决方案可能是添加一个隐藏元素(例如按钮(,并通过Javascript单击它:$('.thebutton'([0].click((;
相关文章:
- JavaScript下拉菜单-点击按钮并根据所选值重定向到url
- Jquery菜单操作不稳定,定位不正确,存在一般错误
- angular的下拉菜单
- 每15天为新用户加载一次放大弹出菜单
- 嵌套放大弹出菜单
- jQuery放大弹出菜单根本不起作用
- 放大弹出菜单-索引错误
- 箭头未显示在放大弹出菜单库中
- 放大弹出菜单未加载到页面的特定部分
- 放大弹出菜单:选择特定的文件类型
- 仅显示第一项的放大弹出菜单
- 指定回车键关闭放大弹出菜单中的按钮
- 汤博乐图片集字幕无法使用放大弹出菜单
- 带有Wordpress图像的放大弹出菜单(php内容)
- 页面加载时的放大弹出菜单
- 谷歌地图:放大/缩小与平移到特定点,如maps.google.com上下文菜单
- 使用表单元素(输入)初始化放大弹出菜单
- PHP-使用放大弹出菜单显示表单提交后的消息
- 放大弹出菜单-添加底部栏
- BackboneJS放大弹出菜单不工作