[英]jQuery image src fadeOut fadeIn effect
I have a problem with this code. 我对此代码有疑问。 It simply does not work.
它根本行不通。 The process ends on fadinOut the image.
该过程在fadinOut图像上结束。 I'm beginner in JS.
我是JS的初学者。
The code: 编码:
$(".intro_lg").click(function() {
$(".intro_lg").fadeOut(1000, function() {
var path = "http://website.com/img/intro2.png";
$(".intro_lg").attr("src", path);
}).fadeIn(1000);
return false;
});
You can try running your code when the page is ready using .ready()
: 您可以在页面准备就绪时尝试使用
.ready()
运行代码:
$(document).ready(function() {
$(".intro_lg").click(function() {
$(this).fadeOut(1000, function() {
var path = "http://website.com/img/intro2.png";
$(this).attr("src", path);
}).fadeIn(1000);
return false;
});
});
And rather than repeating your selectors, use this
instead. 而且,与其重复选择器,不如使用
this
。
Do not use 不使用
$(".intro_lg").fadeOut
use 采用
$(this).fadeOut
because ".intro_lg" is class and can be on another html elements. 因为“ .intro_lg”是类,并且可以在另一个html元素上。 And better way for this is not replace image "src", but hide and show images(exists in dom), because image loading by browser is take time.
更好的方法不是替换图像“ src”,而是隐藏和显示图像(存在于dom中),因为浏览器加载图像需要时间。 for example html:
例如html:
<img src="path1" class="intro_lg" alt=""/>
<img src="path2" class="intro_lg" alt="" style="display: none;"/>
Script: 脚本:
$(".intro_lg").click(function() {
$(this).fadeOut(1000, function() {
$(".intro_lg").next().fadeIn(1000);
});
return false;
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.