javascript - 如何使用 Javascript 检索伪元素转换样式值?

标签 javascript css pseudo-element

情况:

div.xy:hover {
  transform: all rotate(360deg);
  -moz-transform: rotate(360deg);
  -webkit-transform: rotate(360deg);
  -o-transform: rotate(360deg);
}

问题:
我需要检索 360 我可以显示和更改它。 在通往 360 的道路上需要一些帮助。
有什么想法吗?

最佳答案

我相信 document.getElementById('XYZ').style.WebkitTransform 将在 WebKit 浏览器中返回 "rotate(360deg)"。您可以为 Firefox 3.1+ 使用 style.MozTransform,为 IE9+ 使用 style.msTransform,为 Opera 使用 style.OTransform

来源:http://www.zachstronaut.com/posts/2009/02/17/animate-css-transforms-firefox-webkit.html

用鼠标事件绑定(bind)元素:

var e = document.getElementById('test') // Your div ID

e.onmouseover = function(){
    var degree = 360; // Rotation on :hover
    e.style.WebkitTransform = 'rotate(' + degree + 'deg)';
    e.style.MozTransform = 'rotate(' + degree + 'deg)';
    e.style.OTransform = 'rotate(' + degree + 'deg)';
    e.style.msTransform = 'rotate(' + degree + 'deg)';
    e.style.transform = 'rotate(' + degree + 'deg)';
}
e.onmouseout = function(){
    var degree = 0; // Initial rotation
    e.style.WebkitTransform = 'rotate(' + degree + 'deg)';
    e.style.MozTransform = 'rotate(' + degree + 'deg)';
    e.style.OTransform = 'rotate(' + degree + 'deg)';
    e.style.msTransform = 'rotate(' + degree + 'deg)';
    e.style.transform = 'rotate(' + degree + 'deg)';
}

使用 jQuery 可能更简单,但您必须了解您的 JavaScript 根源!

关于javascript - 如何使用 Javascript 检索伪元素转换样式值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9371666/

相关文章:

jquery - 使用 jQuery 隐藏/显示后在 IE 中不可点击/可选择/可聚焦的元素

html - 了解 CSS 字母间距 : is it valid to replace the default value of normal with 0?

css - :after and :before not working on mobile browsers

css - 为什么 div 与 :after gives horizontal scroll to parent element

javascript - 计算连续整数序列的交集?

javascript - 从头开始使用递归 getElementsByClassName

css - 少编译网格列的问题

html - 在 HTML map > area 上定位一个伪元素

javascript - jQuery 插件中对象没有方法 'charAt'

javascript - mongodb组和总和?