PrettyPhoto 触发后重新加载 jQuery 函数
我希望标题是不言自明的。无论哪种方式,我都试图在触发另一个进程后重新加载(或重新读取)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);
遗憾的是,这不起作用。那么,您对触发另一个操作/插件后如何重新加载/重新读取函数有什么想法吗?
谢谢!
克里斯
I hope the title is self-explanatory. Either way, I am trying to reload (or re-read) a function in jQuery, after another process has been triggered (in this case, the prettyPhoto plug-in).
This is my current jQuery function:
/** 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 } ?>
And prettyPhoto gets triggered when an anchor tag with the class fullSize is clicked.
I followed this thread to reload a 'code block', using the setTimeout method. This is what I did: (wrapped the previous code within a function, used setTimeout inside of that function and then called the setTimeout outside of the function)
/** 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);
Sadly that did not work. So, do you have any ideas as to how I could reload/re-read a function once another action/plug-in has been triggered?
Thanks!
Chris
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
“在触发另一个进程后,我正在尝试重新加载(或重新读取)jQuery 中的函数”
为什么要调用 setTimeout?这将在一定时间后触发函数调用,然后每 1000 毫秒循环/重复一次。如果您只想重新加载函数,只需调用函数本身即可。
编辑:
您漂亮的图像可能会影响滚动条。但是,http://www.no- margin-for-errors.com/projects/prettyphoto-jquery-lightbox-clone/documentation/ 具有回调属性。那么,我是否喜欢这样(每当 perryimagee 关闭时,就会调用回调函数,因为您遇到的问题是当它打开 beautifulimage 时。因此,在这方面,这就是为什么单击事件没有解决您的问题(代码可能正在工作))在图像关闭后,您需要一些东西
,并在您的网站的其他地方
工作代码上声明您的侧边栏 http://jsfiddle.net/ qeDwM/
" I am trying to reload (or re-read) a function in jQuery, after another process has been triggered"
why are you calling setTimeout? this will trigger the function call after certain amount of time and then do loop/repeat every 1000ms. If you just want to reload the function, just call function itself.
EDIT:
Your pretty Image probably does something that affects the Scrolbar. However, http://www.no-margin-for-errors.com/projects/prettyphoto-jquery-lightbox-clone/documentation/ has callback attribute. So do ii like this (callback function will be called whenever a perryimaege has been closed as the problem you were having is when it prettyimage gets open. Soin that respect taht's why click event didn't solve your problem (code probably was working)) You needed something AFTEr the image is closed
and declare your sidebar on other place
working code from your webiste http://jsfiddle.net/qeDwM/