久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

變換上的 CSS3 動畫:旋轉.獲取旋轉元素當前度數(shù)的

CSS3 animation on transform: rotate. Way to fetch current deg of the rotating element?(變換上的 CSS3 動畫:旋轉.獲取旋轉元素當前度數(shù)的方法?)
本文介紹了變換上的 CSS3 動畫:旋轉.獲取旋轉元素當前度數(shù)的方法?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

我正在開發(fā)一個使用拖放的 html5 界面.當我拖動一個元素時,目標獲得了一個 css 類,這使得它由于 -webkit-animation 而雙向旋轉.

i am working on a html5 interface wich uses drag and drop. While i am dragging an element, the target gets a css-class, which makes it bidirectionally rotate due to a -webkit-animation.

@-webkit-keyframes pulse {
   0%   { -webkit-transform: rotate(0deg);  }
   25%  { -webkit-transform:rotate(-10deg); }
   75%  { -webkit-transform: rotate(10deg); }
   100% { -webkit-transform: rotate(0deg);  }
  }

.drag
{
    -webkit-animation-name: pulse;
    -webkit-animation-duration: 1s;
    -webkit-animation-iteration-count: infinite;
    -webkit-animation-timing-function: ease-in-out;
}

當我放下目標時,我希望它采用當前的旋轉狀態(tài).

When I drop the target, I want it to adopt the current state of rotation.

我的第一個想法是使用 jquery 和 .css('-webkit-transform') 方法檢查 css 屬性.但是這個方法只返回'none'.

My first thought was to check the css property with jquery and the .css('-webkit-transform') method. But this method just returns 'none'.

所以我的問題是:有沒有辦法獲取通過動畫旋轉的元素的當前度值?

So my question: Is there a way to get the current degree value of an element which is rotated via animation?

到目前為止謝謝亨德里克

Thanks so far Hendrik

推薦答案

我最近不得不寫一個函數(shù)來做你想要的!隨意使用它:

I recently had to write a function that does exactly what you want! Feel free to use it:

// Parameter element should be a DOM Element object.
// Returns the rotation of the element in degrees.
function getRotationDegrees(element) {
    // get the computed style object for the element
    var style = window.getComputedStyle(element);
    // this string will be in the form 'matrix(a, b, c, d, tx, ty)'
    var transformString = style['-webkit-transform']
                       || style['-moz-transform']
                       || style['transform'] ;
    if (!transformString || transformString == 'none')
        return 0;
    var splits = transformString.split(',');
    // parse the string to get a and b
    var parenLoc = splits[0].indexOf('(');
    var a = parseFloat(splits[0].substr(parenLoc+1));
    var b = parseFloat(splits[1]);
    // doing atan2 on b, a will give you the angle in radians
    var rad = Math.atan2(b, a);
    var deg = 180 * rad / Math.PI;
    // instead of having values from -180 to 180, get 0 to 360
    if (deg < 0) deg += 360;
    return deg;
}

希望這會有所幫助!

編輯我更新了代碼以使用 matrix3d 字符串,但它仍然只給出 2d 旋轉度數(shù)(即圍繞 Z 軸旋轉).

EDIT I updated the code to work with matrix3d strings, but it still only gives the 2d rotation degrees (ie. rotation around the Z axis).

這篇關于變換上的 CSS3 動畫:旋轉.獲取旋轉元素當前度數(shù)的方法?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權益,請聯(lián)系我們刪除處理,感謝您的支持!

相關文檔推薦

How do I write FileReader test in Jasmine?(如何在 Jasmine 中編寫 FileReader 測試?)
JS/HTML5 WebSocket: Connect without HTTP call(JS/HTML5 WebSocket:無需 HTTP 調(diào)用即可連接)
CSS: Repeat Table Header after Page Break (Print View)(CSS:分頁后重復表頭(打印視圖))
Put HTML head in another file(將 HTML 頭放在另一個文件中)
What is the real difference between the quot;headquot; and quot;headerquot; tag?(“頭和“頭之間的真正區(qū)別是什么?和“標題標簽?)
Header/Footer Layout with 100% Content Height in IE8(IE8 中具有 100% 內(nèi)容高度的頁眉/頁腳布局)
主站蜘蛛池模板: 久久九| 蜜桃官网 | 91精品国模一区二区三区 | 国产精品久久久久久52avav | 人人干免费 | 免费黄色的视频 | 二区三区视频 | 91亚洲国产成人久久精品网站 | 国产美女特级嫩嫩嫩bbb片 | 亚洲精品av在线 | 日本免费一区二区三区 | 羞羞在线观看视频 | 成人二区 | 一区二区国产精品 | 亚洲精品电影在线观看 | 国产91久久久久久久免费 | 国产一区二区三区久久久久久久久 | 精品一区二区三区中文字幕 | 国产999精品久久久久久 | 午夜在线小视频 | 日本精品一区二区 | 色中文在线 | 欧美日韩一区二区在线播放 | 成人午夜激情 | 一区二区不卡高清 | 免费一区二区 | 国产精品免费小视频 | 狠狠操狠狠色 | 免费视频一区二区 | 人人爽人人爽 | 中文av字幕 | 人人爽人人爽 | 日韩高清中文字幕 | 日本视频在线 | 男女视频在线观看 | 亚洲一区 中文字幕 | av网站推荐| 毛片网站免费观看 | 一a一片一级一片啪啪 | 奇米四色在线观看 | 久久久久久久国产 |