在 jQuery Infinite Carousel 中创建容器调整大小功能
我正在 WordPress 网站 http://cambridgeuplighting.com/scale- 上创建 jquery Infinite Carousel 的自定义实现测试。我想让我的客户可以选择添加任何分辨率的照片,并调整容器元素的大小以适应它。我想要与 Lightbox/Slimbox 或 SimpleViewer 中相同的动画调整大小效果。
我已经有了一个好的开始,但是代码中存在一些缺陷。这是对Infinitecarousel.js中“thumbClick”函数的修改。
//Get the rel attribute of the thumbnail (this is set to the index # of the thumbnail)
var activeLi = $(this).attr('rel');
//Find the Li elemement whose rel attribute (set to the initial index # of the li element onLoad) matches that of the thumbnail, so we can know which image is active
var whichLi = $('#singleSlide ul li[rel='+activeLi+']');
var whichLiImg = $('#singleSlide ul li[rel='+activeLi+'] img');
//Get the width and margin necessary to resize and center the container element
var activeImgWidth = whichLi.width();
var activeImgMargin = 628-activeImgWidth;
//Set the Width attribute of the Li element equal to that of the image it contains
whichLi.css( { 'width' : activeImgWidth } );
//Animate the width of the container element (the div with the gray border)
$('div#singleSlide').animate( {
width: activeImgWidth,
marginLeft: activeImgMargin/2
},300);
这是我添加到自己的init.js中的代码,用于将li元素的rel属性设置为其索引值
jQuery(function( $ ){
$("#singleSlide ul").each(function() {
$(this).children("li").each(function(i) {
$(this).attr("rel", i);
});
});
$('#singleSlide ul li a').attr('rel', 'lightbox-gallery');
});
所以正如您在测试页面上看到的: cambridgeuplighting.com/scale-test,此代码未选择具有正确宽度的正确图像来调整大小。我知道我需要解决的一个问题是,我需要在页面加载时正确设置它们,而不是在单击时设置 Li 宽度。
感谢您的帮助!
I'm creating a custom implementation of jquery Infinite Carousel on a wordpress site, http://cambridgeuplighting.com/scale-test. I want to give my client the option to add photos of any resolution and have the container element resize to fit it. I'm going for the same animated resize effect as in Lightbox/Slimbox or SimpleViewer.
I have got an OK start, but there are some flaws in the code. Here is the modification to the "thumbClick" function in infinitecarousel.js`
//Get the rel attribute of the thumbnail (this is set to the index # of the thumbnail)
var activeLi = $(this).attr('rel');
//Find the Li elemement whose rel attribute (set to the initial index # of the li element onLoad) matches that of the thumbnail, so we can know which image is active
var whichLi = $('#singleSlide ul li[rel='+activeLi+']');
var whichLiImg = $('#singleSlide ul li[rel='+activeLi+'] img');
//Get the width and margin necessary to resize and center the container element
var activeImgWidth = whichLi.width();
var activeImgMargin = 628-activeImgWidth;
//Set the Width attribute of the Li element equal to that of the image it contains
whichLi.css( { 'width' : activeImgWidth } );
//Animate the width of the container element (the div with the gray border)
$('div#singleSlide').animate( {
width: activeImgWidth,
marginLeft: activeImgMargin/2
},300);
Here is the code that I added to my own init.js to set the li elements' rel attribute to their index value
jQuery(function( $ ){
$("#singleSlide ul").each(function() {
$(this).children("li").each(function(i) {
$(this).attr("rel", i);
});
});
$('#singleSlide ul li a').attr('rel', 'lightbox-gallery');
});
So as you can see on the test page: cambridgeuplighting.com/scale-test, This code is not selecting the correct images with the correct widths to resize to. I know one problem i need to fix is instead of setting the Li widths onClick, I need to set them right when the page loads.
Thanks for your help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在我看来,你应该创建一个读取图像大小的变量和一个根据图片大小修改容器大小的类:D
In my opinion you should create a variable that reads the size of the image and a class that modifyes the size of the container according to the size of the picture :D