Howto rotate image using jquery rotate plugin?

强颜欢笑 提交于 2019-11-29 01:31:55

问题


How do you rotate an image using jQuery-rotate plugin?

I have tried the following and it doesn't seem to work:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>View Photo</title>
<script type="text/javascript" src="scripts/jquery.js"></script>
<script type="text/javascript" src="scripts/jquery.rotate.1-1.js"></script>
<script type="text/javascript">
var angle = 0;
setInterval ( function (e) {
    rotate();
}, 100 );
function rotate() {
    angle = angle + 1;
    $('#pic').rotate(angle);
}
</script>
</head>
<body>
<img border="0" src="player.gif" name="pic" id="pic">
</body>
</html>

Other methods that are supported by most browsers are wanted too, thanks!


回答1:


You've got a 404 on jQuery and the jQuery plugin. Because of that, your page is throwing a JavaScript error, that $ is not defined.

You need to learn basic JavaScript debugging techniques. A quick search found this article that looks like a good place for you to start:

  • JavaScript Debugging Techniques with Firebug



回答2:


Your logic for rotating the image is right. It will work if executed when the document is ready.

<script type="text/javascript">
//<![CDATA[
    var angle = 1;

    $(document).ready(function() {
        setInterval(function() {
            $("#pic").rotate(angle);
            /* angle += 1; Increases the rotating speed */
        }, 100);
    });
//]]>
</script>



回答3:


Once you fix your jquery include issues, you can fix your script. Your syntax is wrong: Here is the fix:

<script type="text/javascript">
//<![CDATA[
    var angle = 1;

    $(document).ready(function(angle) {
        setInterval(function(angle) {
                $("#pic").rotate(angle);
                /* angle += 1; Increases the rotating speed */
        }, 100);
    });
//]]>
</script>


来源:https://stackoverflow.com/questions/365820/howto-rotate-image-using-jquery-rotate-plugin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!