- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在构建一个利用 WordPress 和 Zurb Foundation 的自定义画廊:
.previous-sketch
、.next-sketch
链接将显示相应的相邻帖子。我已经设法使上述工作正常进行,但发现在打开一个模式窗口并循环浏览帖子后,事情开始变得不同步。当显示模态窗口时,深色背景 .reveal-modal-bg
不会显示,并且行为有些奇怪。
如果您对此问题有任何特别的见解,我预先感谢您。
更新:我能够在这方面进行更多的工作,并且在大多数情况下它似乎都有效。虽然我觉得我的解决方案不是最优雅的。
我的 jQuery 代码如下。
(function($) {
$.fn.displayPost = function() {
event.preventDefault();
var post_id = $(this).data("id");
var id = "#" + post_id;
// Check if the reveal modal for the specific post id doesn't already exist by checking for it's length
if($(id).length == 0 ) {
// We'll add an ID to the new reveal modal; we'll use that same ID to check if it exists in the future.
var modal = $('<div>').attr('id', post_id ).addClass('reveal-modal').appendTo('body');
var ajaxURL = MyAjax.ajaxurl;
$.ajax({
type: 'POST',
url: ajaxURL,
data: {"action": "load-content", post_id: post_id },
success: function(response) {
modal.empty().html(response).append('<a class="close-reveal-modal">×</a>').foundation('reveal', 'open');
modal.bind('opened', function() {
// Trigger window resize to reset the left margin.
$(window).trigger('resize');
var left;
left = Math.max($(window).width() - $(id).outerWidth(), 0) / 2;
$(id).css({
left:left + $(window).scrollLeft()
});
return false;
});
}
});
}
//If the div with the ID already exists we'll just open it.
else {
$(id).foundation('reveal', 'open');
}
// Recalculate left margin on window resize
$(window).resize(function(){
var left;
left = Math.max($(window).width() - $(id).outerWidth(), 0) / 2;
$(id).css({
left:left + $(window).scrollLeft()
});
});
}
})(jQuery);
// Apply the function when we click on the .reveal link
jQuery(document).on("click", ".reveal,.secondary", function() {
jQuery(this).displayPost();
});
// Use Reveal's built in function to close the div when we click our paging links
jQuery(document).on("click", ".secondary", function() {
var id = jQuery(this).closest("div").attr("id");
jQuery(id).foundation('reveal', 'close');
});
最佳答案
我认为这里有人可能知道更好的方法来做到这一点,但为了其他试图解决这个问题的人,我设法拼凑了一个解决方案。它有效,但我还没有彻底测试过。
该函数通过多种方式扩展了 Foundation 4 Reveal 的功能:
代码如下:
(function($) {
$.fn.displayPost = function() {
event.preventDefault();
var post_id = $(this).data("id");
var id = "#" + post_id;
// Check if the reveal modal for the specific post id doesn't already exist by checking for it's length
if($(id).length == 0 ) {
// We'll add an ID to the new reveal modal; we'll use that same ID to check if it exists in the future.
var modal = $('<div>').attr('id', post_id ).addClass('reveal-modal').appendTo('body');
var ajaxURL = MyAjax.ajaxurl;
$.ajax({
type: 'POST',
url: ajaxURL,
data: {"action": "load-content", post_id: post_id },
success: function(response) {
modal.empty().html(response).append('<a class="close-reveal-modal">×</a>').foundation('reveal', 'open');
modal.bind('opened', function() {
// Reset visibility to hidden and set display: none on closed reveal-modal divs, for some reason not working by default when reveal close is triggered on .secondary links
$(".reveal-modal:not('.reveal-modal.open')").css({'visibility': 'hidden', 'display' : 'none'})
// Trigger resize
$(window).trigger('resize');
return false;
});
}
});
}
//If the div with the ID already exists just open it.
else {
$(id).foundation('reveal', 'open');
}
// Recalculate left margin on window resize to allow for absolute centering of variable width elements
$(window).resize(function(){
var left;
left = Math.max($(window).width() - $(id).outerWidth(), 0) / 2;
$(id).css({
left:left + $(window).scrollLeft()
});
});
}
})(jQuery);
// Apply the function when we click on the .reveal link
// (document).ready won't work on any reveal-modal divs added subsequently
// after page load via AJAX so use .on instead.
jQuery(document).on("click", ".reveal,.secondary", function() {
jQuery(this).displayPost();
});
// Close open modal via secondary paging links; target parent div id.
jQuery(document).on("click", ".secondary", function() {
var id = jQuery(this).closest("div").attr("id");
jQuery(id).foundation('reveal', 'close');
});
更新:添加了用于加载 AJAX 内容的 php 函数
public function __construct() {
add_action( 'wp_ajax_load-content', array($this, 'load_ajax_content' ));
add_action( 'wp_ajax_nopriv_load-content', array($this, 'load_ajax_content' ));
}
/**
* Function to call the content loaded for logged-in and anonymous users
*/
public function load_ajax_content ( $post_id ) {
$post_id = $_POST[ 'post_id' ];
if (has_post_thumbnail($post_id)) {
$sketch_id = get_post_thumbnail_id($post_id);
$attachment = get_post( $sketch_id );
$caption = $attachment->post_excerpt;
$response = '<figure>'. get_the_post_thumbnail($post_id, 'large-sketch') .'<figcaption><p>'. $caption .'</p></figcaption></figure>' . $this->paging_link_nav( $post_id );
echo $response;
}
die(1);
}
希望其他人发现这有用......
关于jquery - Foundation 4 Reveal 和 WP AJAX : Previous/Next Modal Window from Open Modal Window?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17271026/
用于获取所有季度中每个 ID 的 MAX 先前分数的最佳方法。 给定: ID QTR SCORE 21 1 3 21 2 5 21 3 3
我的应用程序包含照片,用户可以搜索符合特定条件的照片。假设某个用户通过标签搜索照片,我们得到如下信息: @results = Photo.tagged_with('mountain') 现在,@res
该表称为 imposto。 +------------------+------------+------+-----+---------+-------+ | Field |
我在这里不知所措。我觉得我已经尝试了所有的方法,并使用了其他帖子/教程中解释的确切方法。我知道您需要使用光标并设置第一个和最后一个可见文档,以便在向前移动的情况下从最后一个文档开始,在向后移动的情况下
Bootstrap容器横向有两种形式。将鼠标悬停在 Form1 上将增加宽度并减少 form2 的宽度。但逆转并没有发生。请提出任何建议。 Bootstrap Example
所以我刚读到我可以定位 previous sibling elements使用 :has(+ ) 伪类。 我去执行了以下规则。不幸的是,这是行不通的。我在祈祷什么吗? p { margin: 2r
我正在制作图像轮播 看我的 fiddle :https://jsfiddle.net/gd2n6paw/8/ 我是 jquery 新手,只是想知道我们如何制作轮播“下一个”和“上一个”控件,感谢您的帮
示例数据: library(dplyr) x % arrange(name,timestamp) 我想找到数据帧 anti_join(y,x) 中每个连续 block (使用 timestam
我尝试了hadoop-1.0.3以及1.0.4。两者都在伪集群模式下。 我的理解是,previous.checkpoint目录应该在由“fs.checkpoint.dir”指定的辅助名称节点下创建吗?
我有一个 MS SQL 表,其中包含具有以下列的股票数据:Id、Symbol、Date、Open、High、Low、Close。 我想自行加入该表,这样我就可以获得关闭的每日百分比变化。 我必须创建一
我正在使用 Selenium IDE 为我的网站编写测试,但我在让 selenium 使用 previous-sibling 单击按钮时遇到了问题 Arcade Reader 我
我有这个脚本: $('#ap').click(function() { $('#content-container').html($('#alertpay').html()); retu
这个问题已经有答案了: how to judge an element's previous or next element exist with jquery? (4 个回答) 已关闭 7 年前。
有没有办法改变浏览器中“上一个”按钮的位置? 问题如下: 用户进入页面 用户点击缩略图 大图像出现在弹出窗口(灯箱)和 URL 更改 来自 http://example.com/至 http://ex
我试图了解回调在这种情况下的工作原理。 例如给定这段代码: var images = jQuery.map((1234567 + '').split(''), function(n) { retu
我似乎无法按照我想要的方式滚动浏览我的 ResultSet : public void getCurves(String runId, File file, Connection conn) {
嗨,我正在使用 jquery mobile,这是代码 parisfrance generique code:24
使用 Apache Commons Collections,我找到了 OrderedMapIterator 接口(interface),可以在 OrderedMap 中来回导航。迭代到下一个条目按预期
我在mysql查询中使用这些代码 select c1.date,sum(SELECT IFNULL(cx.purchase-cx.sold,0))+MAX(p.openqty) as open
我正在尝试从数据库中获取上一张图像,其中图像按 ID 号列出。经过一番研究后,我遇到了这个查询,它应该提供之前的结果。然而它并没有这样做。相反,它提供小于当前 ID 号的第一个结果。 (代码格式为 P
我是一名优秀的程序员,十分优秀!