jQuery放大和缩小不起作用 [英] jQuery Zoom-in and Zoom-Out is not working
本文介绍了jQuery放大和缩小不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图在按下按钮时放大和缩小照片,但是我无法使代码正常工作,我相信这与我构造缩小的方式相同我的代码的一部分.
I am attempting to zoom-in and zoom-out out of a photo when a button is pressed, however I am unable to get the code to work properly I believe this is do to the way i have structured the zoom-out part of my code.
jQuery代码:
$(".enlarge-photo").click(function(){
//photo - zoom-in
var $img = $(".image");
$img.stop().animate({
height: "365",
width: "269",
paddingRight: "12"},"fast");
},function(){
$img.stop().animate({
height: "265",
width: "169",
paddingRight: "0"},"fast");
});
这是我正在使用的HTML:
This is the HTML I am using:
<figure>
<img class="image" src="img/basketball.jpg" width="169" height="265" border="0" alt="basketball dunk"/>
<figcaption>Laura Skelding/AMERICAN-STATESMAN</figcaption>
</figure>
<ul id="photo">
<li rel="nofollow"><a class="enlarge-photo" href="#" title="enlarge-photo">ENLARGE PHOTO</a></li>
</ul>
推荐答案
基于您希望按钮执行此操作的事实:
Based on the fact you want a button to do it:
$("#zoom").button().click(function () {
var options = { height: "365", width: "269", paddingRight: "12"};
var myImage = $("#myImage");
if (myImage.hasClass("zoomed"))
{
options = {height: "265", width: "169"};
}
myImage.stop().animate(options,"fast");
myImage.toggleClass("zoomed");
});
更新的提琴: http://jsfiddle.net/johnkoer/NhYtL/19/
这篇关于jQuery放大和缩小不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文