【发布时间】:2011-04-22 18:28:06
【问题描述】:
我希望标题是不言自明的。无论哪种方式,我正在尝试在另一个进程被触发后重新加载(或重新读取)jQuery 中的一个函数(在本例中为 prettyPhoto 插件)。
这是我当前的 jQuery 函数:
/** Scrolling Sidebar function **/
var $sidebar = $(".sideBar"),
$window = $(window),
$mainImage = $(".mainImage"),
offset = $sidebar.offset(),
threshold = $mainImage.height() - $sidebar.height(),
topPadding = 15;
<?php if ( $options['scroll_sidebar'] == true ) { ?>
if( $mainImage.height() >= 400 ) {
$window.scroll(function() {
if ($window.scrollTop() > threshold) {
if( $('.sideBar').has('.zoomImage').length ) {
$sidebar.stop().animate({
marginTop: threshold + 50
});
} else {
$sidebar.stop().animate({
marginTop: threshold + 60
});
}
} else if ($window.scrollTop() > offset.top) {
$sidebar.stop().animate({
marginTop: $window.scrollTop() - offset.top + topPadding
});
} else {
$sidebar.stop().animate({
marginTop: '40px'
});
}
});
}
<?php } ?>
当一个带有 fullSize 类的锚标签被点击时,prettyPhoto 会被触发。
我跟随this 线程使用 setTimeout 方法重新加载“代码块”。这就是我所做的:(将前面的代码包装在一个函数中,在该函数内部使用 setTimeout,然后在函数外部调用 setTimeout)
/** Scrolling Sidebar function **/
function scrollSidebar() {
var $sidebar = $(".sideBar"),
$window = $(window),
$mainImage = $(".mainImage"),
offset = $sidebar.offset(),
threshold = $mainImage.height() - $sidebar.height(),
topPadding = 15;
<?php if ( $options['scroll_sidebar'] == true ) { ?>
if( $mainImage.height() >= 400 ) {
$window.scroll(function() {
if ($window.scrollTop() > threshold) {
if( $('.sideBar').has('.zoomImage').length ) {
$sidebar.stop().animate({
marginTop: threshold + 50
});
} else {
$sidebar.stop().animate({
marginTop: threshold + 60
});
}
} else if ($window.scrollTop() > offset.top) {
$sidebar.stop().animate({
marginTop: $window.scrollTop() - offset.top + topPadding
});
} else {
$sidebar.stop().animate({
marginTop: '40px'
});
}
});
}
$('a.fullSize').click(function() {
setTimeout(scrollSidebar, 1000);
});
<?php } ?>
}
setTimeout(scrollSidebar, 1000);
很遗憾,这不起作用。那么,一旦触发了另一个动作/插件,您对如何重新加载/重新读取函数有什么想法吗?
谢谢!
克里斯
【问题讨论】: