【发布时间】:2012-08-21 12:50:54
【问题描述】:
这是我的问题:
我用 Jquery Elastislide 插件创建了一个画廊
当我点击拇指时,Hash 出现在图片中......但是当我刷新/重新加载页面作为链接时,Hash 没有加载图片,我希望 Hash 加载相应的图片。
我尝试了一些 Jquery 插件,例如 Address、BBQ、History,但它不起作用。
$(function() {
$.fn.imagesLoaded = function( callback ) {
var $images = this.find('img'),
len = $images.length,
_this = this,
blank = 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==';
function triggerCallback() {
callback.call( _this, $images );
}
function imgLoaded() {
if ( --len <= 0 && this.src !== blank ){
setTimeout( triggerCallback );
$images.off( 'load error', imgLoaded );
}
}
if ( !len ) {
triggerCallback();
}
$images.on( 'load error', imgLoaded ).each( function() {
// cached images don't fire load sometimes, so we reset src.
if (this.complete || this.complete === undefined){
var src = this.src;
// webkit hack from http://groups.google.com/group/jquery-dev/browse_thread/thread/eee6ab7b2da50e1f
// data uri bypasses webkit log warning (thx doug jones)
this.src = blank;
this.src = src;
}
});
return this;
};
// gallery container
var $rgGallery = $('#rg-gallery'),
// carousel container
$esCarousel = $rgGallery.find('div.es-carousel-wrapper'),
// the carousel items
$items = $esCarousel.find('ul > li'),
// total number of items
itemsCount = $items.length;
Gallery = (function() {
// index of the current item
var current = 0,
// mode : carousel || fullview
mode = 'carousel',
// control if one image is being loaded
anim = false,
init = function() {
// (not necessary) preloading the images here...
$items.add('<img src="ajax-loader.gif"/><img src="black.png"/>').imagesLoaded( function() {
// add options
_addViewModes();
// add large image wrapper
_addImageWrapper();
// show first image
_showImage( $items.eq(window.location.hash));
});
// initialize the carousel
if( mode === 'carousel' )
_initCarousel();
},
_initCarousel = function() {
// we are using the elastislide plugin:
// http://tympanus.net/codrops/2011/09/12/elastislide-responsive-carousel/
$esCarousel.show().elastislide({
imageW : 65,
onClick : function( $item ) {
if( anim ) return false;
anim = true;
// on click show image
_showImage($item);
// change current
current = $item.index(location.hash);
that.attr('href')
}
});
【问题讨论】:
-
刷新/重新加载行为会有所不同,具体取决于您在做什么以及您所在的浏览器。最初,如果页面已经加载,则如果存在哈希值,浏览器将不会重新加载页面他们只会滚动到它。在大多数浏览器中按
CTRL+F5将强制无条件重新加载,这应该重新加载页面。 -
我明白了。事实上,我想从 Hash 中获得一个单独的链接。当手动刷新或重新加载页面时,会出现Hash对应的图片。例如,我可以在 Facebook 上发布我的画廊的特定图像的链接。但我没有找到解决这个问题的方法。
标签: jquery url hash anchor responsive-design