[英]jquery image slider gallery
I'm trying to add images dynamically im my preview element.So when I click a thumbnails image will load and slide. 我正在尝试在预览元素中动态添加图像。因此,当我单击缩略图时,图像将加载并滑动。
<div id="imageGallery">
<div id="loading"></div>
<a class="thumbnail"><img alt="Image 1" src="../../baContent/image1.jpg" /></a>
<a class="thumbnail"><img alt="Image 2" src="../../baContent/image2.jpg" /></a>
<div id="preview">
<img id="mainImage" alt="Main Image" src="../../baContent/image1.jpg" />
</div>
</div>
$(document).ready(function () {
$("#loading").show();
var oldImage = $("#preview img:first");
var newImage = $("#mainImage").insertAfter(oldImage).css('position', 'absolute').css('left', 800);
newImage.load(function () {
$("#loading").hide();
oldImage.css({ left: 0 }).animate({ left: -800 });
newImage.css({ left: 800 }).animate({ left: 0 });
oldImage.remove();
});
});
My idea is to insert image dynamically after the first image and old image will remove. 我的想法是在删除第一个图像和旧图像之后动态插入图像。 I try to many functions append,insertTo.
我尝试了许多函数append,insertTo。 But it is not working.Thanks advice :)
但这不起作用,谢谢:)
You're thinking too complicated, I guess... 你想的太复杂了,我想...
$(document).ready(function(){
$(".thumbnail").click(function(){
$("#loading").show();
// Create new image instance
$("<img/>", {
// Get source of image to load
src: $(this).find("img").attr("src")
}).css({
position: "absolute",
left: 800
}).load(function(){
$("#loading").hide();
// Append new image to preview div
$("#preview").append($(this));
// Get current image and animate it
$("#preview").find("img:first").css({
position: "absolute"
}).animate({
left: -800
}, function(){
// Remove the image when animation complete
$(this).remove();
});
// Animate new image
$(this).animate({
left: 0
}, function(){
// Do something interesting...
});
});
});
});
Test it here: http://jsfiddle.net/dpzdL/ 在这里测试: http : //jsfiddle.net/dpzdL/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.