简化 Jquery
我正在尽最大努力简化下面的代码......
您会看到有 3 个不同的图像触发大图像,我想您可以将其称为可点击的幻灯片。我想在用户单击图像时添加预加载的图像。
另外,请记住有 2、3、4 个批次,就像这样。我想让它尽可能干净和轻便。
有什么想法吗?
<html>
<head>
<style type="text/css" media="screen">
#loader.loading {
background: url(http://jqueryfordesigners.com/images/spinner.gif) no-repeat center center;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
<script type="text/javascript">
$("#ml-games-collection .game1-btn").click(function () {
$("#ml-display li.game").removeClass("hide").css("display", "none");
$("#ml-display .game1").show();
});
$("#ml-display .game1-ss1 img").bind("click", function () {
$("#ml-display .game1-large-display").attr({
"alt": "img alt 1 - screenshot 1",
"src": "image 1"
});
});
$("#ml-display .game1-ss2 img").bind("click", function () {
$("#ml-display .game1-large-display").attr({
"alt": "img alt 2 - screenshot 1",
"src": "image 2"
});
});
$("#ml-display .game1-ss3 img").bind("click", function () {
$("#ml-display .game1-large-display").attr({
"alt": "img alt 3 - screenshot 1",
"src": "image 3"
});
});
</script>
</head>
<body>
<div class="column span-20 last game" id="ml-display">
<ul style="padding-bottom:0;" class="game-list no-list-style">
<li class="game1 game" style="">
<div id="loader" class="loading">
<img width="500" height="313" alt="img alt 2 - screenshot 1" src="" class="game1-large-display right">
<ul class="screen-shots no-list-style">
<li><a title="" class="game1-ss1 click"><img alt=" Tiny Screen Shot" src=""></a></li>
<li><a title="" class="game1-ss2 click"><img alt=" Tiny Screen Shot" src=""></a></li>
<li><a title="" class="game1-ss3 click"><img alt=" Tiny Screen Shot" src=""></a></li>
</ul>
</li>
</ul>
</div>
</body>
</html>
I'm trying my hardest to simplifying the code below....
You'll see there's 3 different images that triggers to the large image, I guess you can call it as click-able slideshow. I would like to add a preloaded image when the user clicks the image.
Also, keep in mind there's a 2,3,4 batch just like this. I would like make this clean and light as possible.
Any thoughts?
<html>
<head>
<style type="text/css" media="screen">
#loader.loading {
background: url(http://jqueryfordesigners.com/images/spinner.gif) no-repeat center center;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
<script type="text/javascript">
$("#ml-games-collection .game1-btn").click(function () {
$("#ml-display li.game").removeClass("hide").css("display", "none");
$("#ml-display .game1").show();
});
$("#ml-display .game1-ss1 img").bind("click", function () {
$("#ml-display .game1-large-display").attr({
"alt": "img alt 1 - screenshot 1",
"src": "image 1"
});
});
$("#ml-display .game1-ss2 img").bind("click", function () {
$("#ml-display .game1-large-display").attr({
"alt": "img alt 2 - screenshot 1",
"src": "image 2"
});
});
$("#ml-display .game1-ss3 img").bind("click", function () {
$("#ml-display .game1-large-display").attr({
"alt": "img alt 3 - screenshot 1",
"src": "image 3"
});
});
</script>
</head>
<body>
<div class="column span-20 last game" id="ml-display">
<ul style="padding-bottom:0;" class="game-list no-list-style">
<li class="game1 game" style="">
<div id="loader" class="loading">
<img width="500" height="313" alt="img alt 2 - screenshot 1" src="" class="game1-large-display right">
<ul class="screen-shots no-list-style">
<li><a title="" class="game1-ss1 click"><img alt=" Tiny Screen Shot" src=""></a></li>
<li><a title="" class="game1-ss2 click"><img alt=" Tiny Screen Shot" src=""></a></li>
<li><a title="" class="game1-ss3 click"><img alt=" Tiny Screen Shot" src=""></a></li>
</ul>
</li>
</ul>
</div>
</body>
</html>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将每个图像包裹起来
然后你的JS变成:
Wrap each image an
Then your JS becomes: