【问题标题】:Rotate image interactively以交互方式旋转图像
【发布时间】:2014-04-01 15:02:53
【问题描述】:

是否可以通过鼠标单击来旋转图像?所以我在一个空的 html 页面上有一个图像,并且想要单击并拖动图像,以便它围绕它的中心旋转。 你有代码或工作示例吗?

最好的问候, 马克

【问题讨论】:

    标签: html rotation interactive rotatetransform


    【解决方案1】:

    可以使用java脚本完成。以下只是示例代码。

    <style type="text/css">
      img.primary   { display: inline; }
      img.secondary { display: none; }
      div.foo:hover img.secondary { display: inline; }
      div.foo:hover img.primary   { display: none; }
    </style>
    
    <script type="text/javascript">
    function swapImages(container)
    {
        for(var child in container.childNodes)
        {
            child = container.childNodes[child];
            if(child.nodeName == "IMG")
                child.className = child.className == "primary" ?
                    "secondary" : "primary";
        }   
    }
    
    window.onload = function() {
        // Remove the foo class when the page loads, to disable hover
        var chartArea = document.getElementById("chartArea");
        for(var child in chartArea.childNodes)
        {
            child = chartArea.childNodes[child];
            if(child.nodeName == "DIV" && child.className == "foo")
                child.className = "";
        }
    }
    </script>
    
    <div id="chartArea">
        <div class="foo" onclick="swapImages(this);">
            <img class="primary" src="http://somewhere/piechart1.png" />
            <img class="secondary" src="http://somewhere/barchart1.png" />
       </div>
    
        <div class="foo" onclick="swapImages(this);">
            <img class="primary" ... />
            <img class="secondary" ... />    
        </div>
    
       <div class="foo" ....>
    </div>
    

    【讨论】:

    • 谢谢,但这不是我搜索的内容。我不想交换图像,但要旋转它。所以只需一张图片,通过点击和拖动,我想旋转它,就像我想旋转的汽车的方向盘一样。
    • Link你可能正在寻找这个
    猜你喜欢
    • 1970-01-01
    • 2012-07-24
    • 2018-10-03
    • 2023-03-10
    • 2015-08-24
    • 1970-01-01
    • 2012-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多