作爲藝術家的Wordpress網站的一部分,我做了一個簡單的jQuery圖像交換週期,以在每個個人自定義帖子上使用。從本質上講,只是一張大圖片,下面有一張照片來源,下面有一張七張縮略圖,用來展示藝術作品的不同視角。點擊每個縮略圖將縮略圖中的當前大圖像替換爲href,以及替換照片積分。照片積分使用一個隱藏的div,每個縮略圖中包含.hideText類,其中包含由PHP提供的相關攝影師名稱。在IE8中,在第一次加載時,每個圖像可以按順序點擊以產生相應的大圖像,但是在點擊第七個縮略圖或點擊直線後雖然href仍然正確,但數字序列導致大圖不顯示。注意:使用jQuery 1.8.2和Modernizr 2.6.2。jQuery圖像交換顯示 - IE8的錯誤?
除了IE8的錯誤之外,還有其他三個令人頭痛的問題值得一提。 1)使用.load()會產生緩慢的加載時間,直到圖像被緩存。我想我應該使用預加載器,但不知道如何使用這個設置進行工作。 2)由於大圖像加載緩慢,絕對定位的照片榮譽有時會顯示在錯誤的位置,直到img加載。理想情況下,jQuery照片信用塊將被鏈接以遵循圖像加載代碼以避免這種情況;我試圖使用匿名函數來做到這一點,但無法讓它工作,所以.delay()是一個駭人而不可靠的選擇。 3)點擊後,應該在隱藏舊圖像之前添加#artWrap背景微調框,並在新圖像淡入之後將其刪除,但不能一致地工作。
鑑於意外的時間投資,回想起來我可能會使用WP圖庫插件,但我想了解這個東西。歡迎任何建議!
相關的jQuery:
$('.thumbnail').live("click", function() {
$('#artWrap').css('background-image', "url('../img/ajax-loader-48-48.gif')");
$('#artLarge').hide();
var i = $('<img />').attr('src',this.href).load(function() {
$('#artLarge').attr('src', i.attr('src'));
$('#artLarge').fadeIn(200);
$('#artWrap').css('background-image', 'none');
});
if ($(this).find('.hideText').is(':empty')) {
$('#photoCredit').hide().empty();
} else {
$('#photoCredit').hide().empty();
var newCredit = $(this).find('.hideCredit').html();
$('#photoCredit').html(newCredit).delay(600).fadeIn(200);
}
return false;
});
...
基本的div結構:
<div id="artShow">
<div id="artWrap" >
<div id="artImage">
<img id="artLarge" src="../uploads/EXAMPLE_1-LG.jpg">
</div><!-- #artImage -->
<div id="photoCredit">
Photo: Example 1 Photographer
</div><!-- .artCredit -->
</div><!-- #artWrap -->
<div id="artThumbs" class="clearfix">
<div id="thumb1" class="thumb">
<a href="../uploads/EXAMPLE_1-LG.jpg" class="thumbnail nofancybox"><!-- large image link goes in href here -->
<img src="../uploads/EXAMPLE_1-SM.jpg" width="72" height="72" ><!-- small image -->
</a>
<div class="hideCredit">Photo: Example 1 Photographer</div>
</div><!-- #thumb1 -->
<div id="thumb2" class="thumb">
<a href="../uploads/EXAMPLE_2-LG.jpg" class="thumbnail nofancybox">
<img src="../uploads/EXAMPLE_2-SM.jpg" width="72" height="72" >
</a>
<div class="hideCredit">Photo: Example 2 Photographer</div>
</div><!-- #thumb2 -->
<div id="thumb3" class="thumb"> ... ETC ... </div>
<div id="thumb4" class="thumb"> ... ETC ... </div>
<div id="thumb5" class="thumb"> ... ETC ... </div>
<div id="thumb6" class="thumb"> ... ETC ... </div>
<div id="thumb7" class="thumb"> ... ETC ... </div>
</div><!-- #artThumbs -->
</div><!-- #artShow -->
...
Pe的rtinent CSS:
/* Content shell for whole image swap show */
#artShow { float: right; position: relative; width: 630px; min-height: 570px; }
/* wrap for both image and photo credit */
#artWrap { float: left; position: relative; background: url('../img/ajax-loader-48-48.gif') center center no-repeat; }
/* wrapper for large image */
#artImage { min-height: 456px; margin-bottom: 19px; line-height: 0; /* lh adjusts photo credit */ }
/* ID attached to large img */
#artLarge { }
/* photo credit below artImage */
#photoCredit {
position: absolute;
right: 0;
bottom: -5px;
height: 16px;
padding-top: 3px;
width: 100%;
text-align: right;
}
#artThumbs { position: absolute; top: 492px; left: 0; width: 651px; height: 72px; }
.thumb { float: left; margin-right: 21px; width: 72px; height: 72px; background-color: #c9c9c9; }
.thumbnail { display: block; width: 72px; height: 72px; }
瀏覽器控制檯中是否有錯誤? – Spudley 2013-03-23 19:24:38
@Spudley在這裏似乎沒有適用。使用FF,唯一的JS是在頁面的單獨部分用於音頻。我認爲唯一相關的CSS是用於未知的背景微調。曾嘗試使用IE8中的Windows開發工具以及IE9 w/IE8兼容模式來查看它們是否提出了不同的錯誤,但沒有拋出任何我能分辨的東西(但我不熟悉這些控制檯)。你可以在這裏檢查登臺網站上的行爲:http://alisonmoritsugu.com/amwp/work/log-series/red-cabbage/ – boomturn 2013-03-23 20:50:00