在 jQuery 工具中将 fadeTo() 更改为 fadeIn() 时遇到问题
我正在使用 具有此设置的 jQuery Tools Scrollable。我在更改大图像的过渡效果时遇到问题。
当您单击缩略图时,大图像会淡出和淡入(您可以在演示中看到此行为 访问链接)。我只将大图像淡入。
我认为这就像将 var wrap = ... fadeTo()
中的转换更改为 fadeIn()
一样简单,但事实并非如此。我还更改了 wrap.fadeTo()
行上的转换,但这不起作用。
有什么想法吗?我从示例中删除了不必要的代码...
$(function() {
$(".scrollable").scrollable();
$(".items img").click(function() {
if ($(this).hasClass("active")) { return; }
var url = $(this).attr("src").replace("_t", "");
var wrap = $("#image_wrap").fadeTo("medium", 0.5);
var img = new Image();
img.onload = function() {
wrap.fadeTo("fast", 1);
wrap.find("img").attr("src", url);
};
img.src = url;
$(".items img").removeClass("active");
$(this).addClass("active");
}).filter(":first").click();
});
HTML
<div id="image_wrap">Large image goes here</div>
<div class="scrollable">
<div class="items">
<div>
thumbnails go here
</div>
</div>
</div>
I'm using jQuery Tools Scrollable with this setup. I'm having trouble changing the transition effect on the large image.
When you click a thumbnail, the large image fades out-and-in (you can see this behaviour in the demo by visiting the link). I the large image to fade in, only.
I assumed it's as simple as changing the transition in var wrap = ... fadeTo()
to fadeIn()
, but that's not the case. I also changed the transition on the wrap.fadeTo()
line, and that did not work.
Any ideas why? I snipped unnecessary code from my example...
$(function() {
$(".scrollable").scrollable();
$(".items img").click(function() {
if ($(this).hasClass("active")) { return; }
var url = $(this).attr("src").replace("_t", "");
var wrap = $("#image_wrap").fadeTo("medium", 0.5);
var img = new Image();
img.onload = function() {
wrap.fadeTo("fast", 1);
wrap.find("img").attr("src", url);
};
img.src = url;
$(".items img").removeClass("active");
$(this).addClass("active");
}).filter(":first").click();
});
HTML
<div id="image_wrap">Large image goes here</div>
<div class="scrollable">
<div class="items">
<div>
thumbnails go here
</div>
</div>
</div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
什么是
img
?并且您无法将.load()
函数添加到已加载的内容中,而且如果您将多个.load()
函数添加到 1 个元素,它也会加载后,之前绑定的所有.load()
函数也会被调用。也许您不想在调用
.fadeTo()
方法之前执行.stop(true, false)
,因为如果您已经褪色,它会停止它,清除队列并淡入新位置。所以你不必等到它部分加载。更新
如果您不想淡出,而只想淡入淡出,请使用以下命令:
What is
img
? And you can't add a.load()
function to something that is already loaded, also if you add multiple.load()
functions to 1 element and it will be loaded, all the.load()
functions that you binded before will also be called.And maybe you wan't to do a
.stop(true, false)
before you call the.fadeTo()
methods, because if your already fading, it stops it, clears the queue and fades to the new position. So you don't have to wait untill it is partialy loaded.Update
If you don't want the fadeout, but only the fade in use this: