我正在使用一个Jquery脚本来做鼠标悬停时的预览图像,但我遇到了这个脚本只能在两个第一张图像中运行的问题。预览图像jquery脚本运行不好
要访问我实现了网络:http://81.35.152.41:8888/index.php/ca/dinamic/coleccions
我认为这个问题是因为我打印从德jQuery脚本的HTML代码,因为我使用Ajax和JSON与jQuery。
这是打印的html代码Jquery的:
(function($) {
$(document).ready(function(){
id=$("#colecciochange option:first").val()
getcoleccions(id);
//getpuntosdeventa(1);
$("#colecciochange").change(function(){
getcoleccions($(this).val())
});
function getcoleccions(id)
{
$("ul.appends").empty()
$("div.descripcio").empty()
$.getJSON('<?php echo url_for('ajax/coleccio/?id=',true)?>'+id, function(data) {
$.each(data.items, function(key,val) {
//items.push('<p>' + val.nombre + ','+val.direccion + ','+val.ciutad +'</p>');
//$("ul.appends").append('<li><a href=' +val.foto_g + ' class="preview" title><img src='+val.foto_th +' alt="prova" /></a></li>');
$("#galeria").append('<li><a href="/1.jpg" id="1" class="preview"><img src="/1s.jpg" alt="gallery thumbnail" /></a></li>');
});
$("div.descripcio").append('<p>' +data.nom_coleccio + '</p>');
});
}
});
})(jQuery)
这是做图像预览脚本:
this.imagePreview = function(){
/* CONFIG */
xOffset = 10;
yOffset = 30;
// these 2 variable determine popup's distance from the cursor
// you might want to adjust to get the right result
/* END CONFIG */
console.log($(this).attr("id"));
$("a.preview").hover(function(e){
console.log($(this).attr("id"));
this.t = this.title;
this.title = "";
var c = (this.t != "") ? "<br/>" + this.t : "";
$("body").append("<p id='preview'><img src='"+ this.href +"' alt='Image preview' />"+ c +"</p>"); var id=($(this).attr("id"));
$("#preview")
.css("top",400 + "px")
.css("left",150 + "px")
.fadeIn("fast");
},
function(){
this.title = this.t;
$("#preview").remove();
});
/*$("a.preview").mousemove(function(e){
console.log($(this).attr("id"));
$("#preview")
.css("top",400 + "px")
.css("left",150 + "px")
});*/
$("a.preview").click(function(event) {
event.preventDefault();
//
});
};
$(document).ready(function(){
imagePreview();
});
当是什么问题?
感谢
问候
为什么你不能发布相关的代码和HTML而不是让人们去不同的网站? – Oded 2012-02-18 10:43:57
好的,对不起,走吧! – 2012-02-18 10:48:14
对不起,我如何编辑帖子? – 2012-02-18 10:49:01