上我是一個jQuery新手,所以這個問題的答案可能很簡單:jQuery的 - 運行功能的新形象
我有一個形象,我願做幾件事情吧。 當用戶點擊「縮放」圖標時,我正在運行'imagetool'插件(http://code.google.com/p/jquery-imagetool/)以加載更大版本的圖像。該插件在圖像周圍創建一個新的div,並允許用戶平移。
當用戶點擊一個替代圖像上,我卸下在新的舊的和負載。
,當用戶點擊一個替代圖像,然後點擊縮放按鈕問題就來了 - 該插件ImageTool的創建新的div,之後卻出現圖像...
的代碼如下:
// Product Zoom (jQuery)
$(document).ready(function(){
$("#productZoom").click(function() {
// Set new image src
var imageSrc = $("#productZoom").attr("href");
$("#productImage").attr('src', imageSrc);
// Run the imagetool plugin on the image
$(function() {
$("#productImage").imagetool({
viewportWidth: 300,
viewportHeight: 300,
topX: 150,
topY: 150,
bottomX: 450,
bottomY: 450
});
});
return false;
});
});
// Alternative product photos (jQuery)
$(document).ready(function(){
$(".altPhoto").click(function() {
$('#productImageDiv div.viewport').remove();
$('#productImage').remove();
// Set new image src
var altImageSrc = $(this).attr("href");
$("#productZoom").attr('href', altImageSrc);
var img = new Image();
$(img).load(function() {
$(this).hide();
$('#productImageDiv').append(this);
$(this).fadeIn();
}).error(function() {
// notify the user that the image could not be loaded
}).attr({
src: altImageSrc,
id: "productImage"
});
return false;
});
});
在我看來,該插件ImageTool的不能再看到#productImage形象一旦被替換成一個新的形象。所以我覺得這事做結合?由於在頁面加載後新圖像被添加到dom中,iamgetool插件不能再正確使用它了......是嗎? 如果是這樣,任何想法如何處理?
謝謝,但沒有工作,要麼......做同樣的事情,雖然可能是做什麼我最初做的更好的方法。 ;) – 2008-09-25 12:04:16