最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - jQuery -webkit-transform yAngle - Stack Overflow

programmeradmin4浏览0评论

Just as a learning experience, I am trying to make en element rotate on its yAxis upon clicking a link, but I am having no luck. Here is the code I am using. Any ideas?

$('rotate').click(function(){

$('object').style.webkitTransform = "rotateY(90deg)";});

Just as a learning experience, I am trying to make en element rotate on its yAxis upon clicking a link, but I am having no luck. Here is the code I am using. Any ideas?

$('rotate').click(function(){

$('object').style.webkitTransform = "rotateY(90deg)";});
Share Improve this question asked Nov 17, 2010 at 3:49 mcbeavmcbeav 12.3k19 gold badges58 silver badges88 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 9

That's not how you apply CSS styles with jQuery. This is.

$('rotate').click(function ()
{
    $('object').css('-webkit-transform', 'rotateY(90deg)');
    // or this:
    // $('object').attr('style', '-webkit-transform: rotateY(90deg)');
});

.style isn't a jQuery object property, if you wanted to affect one, use [0] like this:

$('.rotate').click(function(){
  $('.object')[0].style.webkitTransform = "rotateY(90deg)";
});

Or, to affect all of them use a .each():

$('.rotate').click(function(){
  $('.object').each(function() {
    this.style.webkitTransform = "rotateY(90deg)";
  });
});

Note that your selectors 'rotate' and 'object' are looking for <rotate> and <object> elements...so you'll want to adjust those selectors accordingly, above I'm looking for class="rotate" for the click, etc.

An alternative more jQuery-ish way (debatable for custom properties) is .css(), like this:

$('.rotate').click(function(){
  $('.object').css("webkitTransform", "rotateY(180deg)");
});

You can test it here.

The QTransform jQuery plugin extends jQuery's css to include setting css Transforms. You can write: $('object').rotate('30deg'); or animate with $('object').animate({rotate:'+=30deg', 1000});

http://plugins.jquery./project/QTransform

发布评论

评论列表(0)

  1. 暂无评论